问题
The official documentation page for PDO DSN does not list out username or password yet. What is the correct name for these key-value pairs?
回答1:
Looks like the documentation hasn't been updated yet, but this is the related change from PHP's source repository, stating how it should be used:
PDO: The username and password can now be specified as part of the PDO DSN for the mysql, mssql, sybase, dblib, firebird and oci drivers. Previously this was only supported by the pgsql driver. If a username/password is specified both in the constructor and the DSN, the constructor takes precedence.
new PDO("mysql:host=xxx;port=xxx;dbname=xxx;user=xxx;password=xxx");
And here's the associated pull request.
来源:https://stackoverflow.com/questions/59448952/how-to-specify-username-and-password-in-the-dsn