0PricingLogin
PHP Academy · Lesson

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

  1. Connecting to MySQL with PDO
  2. Prepared Statements and Binding
  3. Fetching Results with PDO
  4. Transactions with PDO
← Back to PHP Academy