Skip to content
PHP Logo

What are common causes of the PDO error "SQLSTATE[HY093]: Invalid parameter number" in PHP?

The "SQLSTATE[HY093]: Invalid parameter number" PDO error in PHP commonly occurs when the number of placeholders in the SQL query does not match the number of parameters provided in the bindValue or execute function. To solve this issue, make sure that the number of placeholders in the query matches the number of parameters being bound.

php
// Example of how to fix the "SQLSTATE[HY093]: Invalid parameter number" PDO error
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id AND name = :name");
$stmt->bindValue(':id', $id);
$stmt->bindValue(':name', $name);
$stmt->execute();