connection pdo code example
Example 1: pdo db connection
<?php
$pdo = new PDO('mysql:host=localhost;dbname=databasename', 'username', 'password');
?>
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;
}
Example 3: PDO connect
<?php
$db = new PDO('mysql:host=myhost;dbname=mydb', 'login', 'password');