如何在 DSN 中指定用户名和密码?

How to specify username and password in the DSN?

PDO DSN 的官方文档页面尚未列出用户名或密码。这些键值对的正确名称是什么?

看起来文档还没有更新,但是 this is the related change 来自 PHP 的源存储库,说明了它应该如何使用:

  • 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");
    

这是 associated pull request