php pdo database connection class code example
Example 1: php pdo connection
$host = "localhost";
$user = "root";
$pass = "qwerty";
$dbname = "DB";
try {
$connection = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e)
{
echo $e->getMessage();
}
Example 2: pdo db connection
<?php
$pdo = new PDO('mysql:host=localhost;dbname=databasename', 'username', 'password');
?>
Example 3: php pdo sql server connect
$db = new PDO("sqlsrv:Server=YouAddress;Database=YourDatabase", "Username", "Password");