$db = new PDO("mysql:host=localhost;dbname=test", "user", "password"); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db = new PDO("mysql:host=localhost;dbname=test", "user", "password"); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$db = new PDO("mysql:host=localhost;dbname=test", "user", "password"); $db->setAttribute(PDO::ATTR_SERVER_VERSION, "5.7.30");In this example, the database server version is set to "5.7.30". This is useful when we need to know the exact database server version we are working with. The PDO extension is part of the PHP core, and it is available in all PHP installations. Therefore, no external package or library is required to use PDO.