pdo connexion 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 connexion
public static function connexionBDD()
{
$base = null;
try {
$base = new PDO('mysql:host=' . MYSQL_HOSTNAME . '; dbname=' . MYSQL_DATABASE . '', MYSQL_USERNAME, MYSQL_PASSWORD);
} catch (exception $e) {
die('Erreur ' . $e->getMessage());
}
return $base;
}