$stmt = $dbh->prepare("SELECT * FROM users WHERE id = ?"); $stmt->execute([$user_id]); if (!$stmt) { $error_info = $dbh->errorInfo(); echo "Error " . $error_info[1] . ": " . $error_info[2]; }
try { $stmt = $dbh->prepare("INSERT INTO users (name, email) VALUES (?, ?)"); $stmt->execute([$name, $email]); } catch (PDOException $e) { $error_info = $dbh->errorInfo(); echo "Error " . $error_info[1] . ": " . $error_info[2]; }Package Library The PDO extension is included in the core PHP package, so no additional packages or libraries are required.