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

标签 php pdo php-7.4

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 .

关于php - 如何在 DSN 中指定用户名和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59448952/

相关文章:

php - 包含 '.' 和 '+'/'-' 的未加括号的表达式的行为将在 PHP 8 : '+' /'-' will take a higher precedence 中发生变化

php - 如何使用 PDO 设置时区

mysql - 如何在一个数据库请求中计算不同的 mysql 行?

PHP/MySQL 根据第二个表中 X 行中的 1 选择一个列表

javascript .replace 和 .trim 在 vuejs 中不起作用

php - 检查值是否存在大小写字母

floating-point - PHP 8 浮点小数点不同于 PHP 7

PHP 7.4类型化属性迭代

php - wordpress 在注册表中上传简历文件

php - 无法将两个数组合并为一个来获取 SQL 查询