Page 1 of 1

PHP, PDO and Database platforms

Posted: Wed Dec 12, 2007 11:14 am
by KBleivik
PDO is the new PHP Data Object extension introduced with PHP 5.0 that is much safer than the traditional model since the connection to the data base server is encapsulated. Communication with the data base server takes place through the PDO object.

PHP supports all the important relational databases including Oracle, IBM's DB2, Microsoft's SQL Server and Sybase to name a few. It also supports the open software database platforms like SQLite, PostgreSQL and MySQL.

Example: Connecting to a MySQL data base server.

Code: Select all

<?php
$dsn = 'mysql:host=hostName; dbname=databasName;';
$user='userName';
$Password ='passWord';
try
{
$dbh = new PDO($dsn, $user, $password);
}
catch (PDOException $e)
{
echo 'Connection failied: ' . $e->getMessage();
}
?>
Links:
http://www.php.net/pdo

http://www.php.net/manual/en/ref.pdo.php

http://www.php.net/manual/en/ref.pdo.php#pdo.drivers