Framework Error
Invalid parameter type: expected array for 'where' clause, got string
What This Error Means
This error occurs when the SQL framework expects an array of parameters for the 'where' clause, but a string is passed instead.
Why It Happens
This error typically happens when using an ORM (Object-Relational Mapping) library, such as Doctrine, and passing a string as a parameter to a query method that expects an array. This can be due to a misunderstanding of the library's API or a simple typo.
How to Fix It
- 1To fix this error, make sure to pass an array of parameters to the query method. For example, instead of passing a string like `where='age > 18'`, pass an array like `where=['age > 18']`. Alternatively, you can use the library's API to specify the parameter type correctly.
Example Code Solution
❌ Before (problematic code)
SQL
$query = $db->prepare('SELECT * FROM users WHERE age > 18');
$query->execute(['where' => 'age > 18']);✅ After (fixed code)
SQL
$query = $db->prepare('SELECT * FROM users WHERE age > 18');
$query->execute(['where' => ['age > 18']]);Fix for Invalid parameter type: expected array for 'where' clause, got string
Browse Related Clusters
Related SQL Errors
Related SQL Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error