PDO Database Source Name
The PDO Database Source Name (DSN) is essential part of the connecting to a database using PDO. The DSN tells PDO which database to connect to.
The first part of the DSN is identifies the PDO driver to use. Remember that PDO is a database independent and can be used by a number of different database management systems, so it is important inform PDO which one will be used.
The PDO driver is followed by a series of key/value paris each separated by a semicolon. Each PDO driver will use slightly different key/value pairs. For this class, we will be focusing on the MySQL database, so the DSN will look something like this:
$dsn = 'mysql:host=localhost;dbname=movies';
NOTE
The host
and dbname
are required for connecting to MySQL database using PDO. A port
value can also be used.
The DSN is only first part of the connecting to the database using PDO. On the next, we will learn how to use the DSN with the PDO class to create a connection.