$db = DB::getPdo(); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Specify the database driver, host, database name, username, and password $dsn = 'mysql:host=localhost;dbname=mydatabase'; $username = 'myusername'; $password = 'mypassword'; // Connect to the database using PDO $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8"); $db = new PDO($dsn, $username, $password, $options);
$query = $db->prepare('SELECT * FROM customers WHERE id=?'); $query->execute([$id]); // Retrieve the result set as an associative array $result = $query->fetchAll(PDO::FETCH_ASSOC);
$query = $db->prepare('INSERT INTO customers (name, email, phone) VALUES (?, ?, ?)'); $query->execute([$name, $email, $phone]);The package/library that contains the DB getPdo function is likely a database access library such as Doctrine DBAL, Zend DB, or Laravel Eloquent.