I’m learning about PDO, and the constructor seems to use an unorthodox and inconsistent way to take arguments. Namely:
$dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
Why is different than the usual format:
$dbh = new PDO("mysql", $host, $dbname, $user, $pass);
Or since the first two arguments (host and dbname) are written as one long string, why not continue that with the remaining two arguments? Namely:
$dbh = new PDO("mysql:host=$host;dbname=$dbname;user=$user;pass=$pass");
The DSN describes where the data source resides and how to connect to it. User and pass are authentication parameters which do not have any affect on how the data source is accessed.
Having user and pass in the DSN would be like requiring your username and password in the url of a website you’re going to.