Why is PHP PDO DSN a different format for MySQL versus PostgreSQL?
mysql, pdo, php, postgresql
Solution
As the person that implemented both, I can tell you that the reason is that by passing the string through as-is to postgres (and ODBC) the PDO driver code for those databases does not need to be updated as the underlying library adds new features.
Since MySQL does not have its own connection string parsing code, we invented a mechanism for passing data in to the underlying MySQL function calls, which have a very specific API with fixed parameters.
No accident; it's very deliberate.
Problem
When I connect to a MySQL database using PDO, the way I need to connect is: ``` $pdoConnection = new PDO("mysql:host=hostname;dbname=databasename",user,password); ``` But, for PostgreSQL, the DSN is more standard (IMO): ``` $pdoConnection = new PDO("pgsql:host=hostname;dbname=databasename;user=username;password=thepassword"); ``` Is there any reason why MySQL cannot use a single string? Or is this just because of the versions I am using (PHP 5.2, MySQL 5.0, PostgreSQL 8.1)?