Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php try { $stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id"); $stmt->execute(["id" => $id]); $user = $stmt->fetch(); } catch (PDOException $e) { // PDOException has an errorInfo array: [SQLSTATE, driver code, driver message] $errorInfo = $e->errorInfo; error_log("SQL Error [{$errorInfo[0]}]: {$errorInfo[2]}"); // Specific SQLSTATE codes if ($e->getCode() === "23000") { throw new DuplicateEntryException("Record already exists"); } throw new DatabaseException("Query failed", 500, $e); }
Result
Open