Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php $stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id"); $stmt->execute(["id" => $id]); // Single row as associative array $user = $stmt->fetch(PDO::FETCH_ASSOC); // All rows $users = $stmt->fetchAll(PDO::FETCH_ASSOC); // Into a class (auto-populates public properties) $user = $stmt->fetch(PDO::FETCH_CLASS, User::class); // Single column value $name = $pdo->query("SELECT name FROM users WHERE id = 1")->fetchColumn(); // Count $total = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
Result
Open