Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify username and password in the DSN?

Tags:

php

pdo

php-7.4

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?

like image 654
Dharman Avatar asked Dec 22 '19 23:12

Dharman


1 Answers

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.

like image 189
Jeto Avatar answered Nov 14 '22 23:11

Jeto