PHP PDO
PDO (PHP Data Objects) is a database abstraction layer that provides a consistent interface for multiple database drivers. It is more secure and flexible than the old mysql_* functions.
PDO (PHP Data Objects) is a database abstraction layer that provides a consistent interface for multiple database drivers. It is more secure and flexible than the old mysql_* functions.
<?php
// Supported databases: MySQL, PostgreSQL, SQLite, MSSQL, Oracle, and more
// Change the DSN to switch databases — your code stays the same
// MySQL
$pdo = new PDO("mysql:host=localhost;dbname=mydb;charset=utf8mb4", "user", "pass");
// SQLite (no credentials needed)
$pdo = new PDO("sqlite:/path/to/database.db");
// PostgreSQL
$pdo = new PDO("pgsql:host=localhost;dbname=mydb", "user", "pass");
Always set the charset in the MySQL DSN (charset=utf8mb4) — never use SET NAMES after connecting.