$pdo = new PDO("mysql:host=localhost;dbname=test", "username", "password"); $stmt = $pdo->query("SELECT COUNT(*) FROM users"); $count = $stmt->fetchColumn(); echo "There are $count users in the database.";
$pdo = new PDO("sqlite:data.db"); $stmt = $pdo->prepare("SELECT name FROM documents WHERE id = ?"); $stmt->execute([42]); $name = $stmt->fetchColumn(); echo "The name of document 42 is $name.";This example fetches the name of the document with ID 42 from a SQLite database and displays it on the page. The PDO library is a core PHP package and does not require any separate installation or configuration.