Username and Password in PDO DSN

To connect to a database, you (hopefully) have to specify a username and password. Since PHP 7.4, when using pdo to connect to the database, you specify the username and password as part of the DSN:

new PDO('mysql:host=localhost;port=3306;dbname=test;user=thephpcc;password=*******');

We always use ******* as password, by the way.

Before PHP 7.4, specifiying username and password only was possible when connecting to a PostgreSQL database. Note that specifying username and password as constructor parameters is still possible:

new PDO('mysql:host=localhost;port=3306;dbname=test', 'thephpcc', '*******');

Username and password specified in the constructor have precedence over the DSN.