views:

1916

answers:

2

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)?

A: 

It's just an accident that the person who implemented the mysql connector did it differently than the person who implemented the pgsql connector.

Glomek
+15  A: 

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.

Wez Furlong
You can't argue with Wez's answer...how has this not been accepted yet? :)
TML
Thanks for the detailed response!
Kevin Peno