Connecting to MySQL with PDO
Create a PDO connection with DSN, user, and password.
What is PDO?
PDO (PHP Data Objects) is a database-access abstraction layer. One API works with MySQL, PostgreSQL, SQLite, and more — just change the DSN.
The DSN
A DSN (Data Source Name) string identifies the driver, host, port, and database name.
<?php
$dsn = "mysql:host=127.0.0.1;port=3306;dbname=myapp;charset=utf8mb4";All lessons in this course
- Connecting to MySQL with PDO
- Prepared Statements and Binding
- Fetching Results with PDO
- Transactions with PDO