Snippets Collections
$host = '127.0.0.1';
$db   = 'test';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];
try {
     $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
     throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
star

Wed Sep 14 2022 13:34:16 GMT+0000 (Coordinated Universal Time) https://phpdelusions.net/pdo

#mysql #bd #pdo #php

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension