What is PDO
What is PDO?
PDO stands for PHP Data Objects and is an interface software that allows us to access the database in a very lightweight and consistent manner. PDO is a system worthy of its name, featuring an Object Oriented Programming interface and supporting dozens of database drivers. Some of the database drivers it supports
- Cubrid
- FreeTDS/Microsoft SQL Server / Sybase
- Firebird / Interbase 6
- IBM DB2
- IBM Informix Dynamic Server
- MySQL 3.x/4.x/5.x
- Oracle Call Interface
- PostgreSQL
- SQLite 3 and SQLite 2
- SQL Azure
With PDO, you can use all the features you use in systems like MySQL and MySQLi, and you can do so very simply.
Note: To use PDO, you need PHP 5.1 or later versions.
Connecting to MYSQL with PDO
Connecting to MYSQL with PDO is quite simple,
$db = new PDO('mysql:host=localhost;dbname=test', $user, $pass); When using PDO, you should be careful to use it within a Try / Catch structure.
$dsn = 'mysql:host=localhost;dbname=test';
$user = 'dbuser';
$password = 'mypassword';
try {
$db = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}

Yorum Gönder