PHP PDO uses this style:
MySQL
mysql:host=hostname;dbname=databasename
with username and password in their own separate parameters
PostgreSQL
pgsql:host=hostname;dbname=databasename;user=username;password=password
But then when search Github for a DSN parser, they seem to use a different format altogether, like this:
mysql://user:pass@hostname:port/databasename
My question is, is there actually a standard DSN format that every language accepts?
Let's see what is actually DSN?
DSN stands for Data Source Name. But this is also known as Database Source Name. DSN
term also overlaps with connection string. Most systems do not make a distinction between DSNs
or connection strings
and the term can often be used interchangeably.
DSN attributes may include, but are not limited to:
The information is above taken from wiki
In general, the following format of a connection string is maintained by many languages for database connections. This may be a community standard. But I didn't see any specification of DSN
.
scheme://username:password@host:port/dbname?param1=value1¶m2=value2&...
There are several ways to connect to a database. So there are some common attributes that are used for all types of database connections. See the following examples:
Connect to database through a socket
mysql://user@unix(/path/to/socket)/dbname
Connect to database on a non standard port
pgsql://user:pass@tcp(localhost:5555)/dbname
Connect to SQLite on a Unix machine using options
sqlite:////full/unix/path/to/file.db?mode=0666
Connect to SQLite on a Windows machine using options
sqlite:///c:/full/windows/path/to/file.db?mode=0666
Connect to MySQLi using SSL
mysqli://user:pass@localhost/pear?key=client-key.pem&cert=client-cert.pem
Connecting to MS Access sometimes requires admin as the user name
odbc(access)://admin@/datasourcename
Connecting to ODBC with a specific cursor
odbc(access)://admin@/datasourcename?cursor=SQL_CUR_USE_ODBC
Here I am providing two links for PostgreSQL and MySQL respectively. You will find there how they use connection string
to connect a database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With