PHP, PDO and Database platforms

Post Reply
KBleivik
Site Admin
Posts: 88
Joined: Tue Jan 31, 2006 3:10 pm
Location: Moss Norway
Contact:

PHP, PDO and Database platforms

Post 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
Kjell Gunnar Bleivik
Make it simple, as simple as possible but no simpler: | DigitalPunkt.no |

Post Reply