Unhandled Exception. SQLSTATE[HY093]: Invalid parameter number You can find the error back in the log

Hi there!

I got an error:

Unhandled Exception.
SQLSTATE[HY093]: Invalid parameter number
You can find the error back in the log.

My sql is;

$TotalHaiguis = $DB->query('SELECT * FROM ' . PREFIX . 'users FORCE INDEX(PRI)
	WHERE NationOfTurtle = :State_name OR Province = :State_name And UserRoleID = 2 And UserAccountStatus = 1',
			array(
					'State_name' => $State_name
			)
			);

How to improve my sql?

I think you’d need to use prepare() then execute() to do what you’re doing, this is complaining about the array you passed in to query() as the second parameter - as the doc to query() shows, none of the options for that function involve passing an array as the second parameter. Presumably that’s what it says in the log, did you have a look as the error message points you to?

But when you’ve changed that, you can’t use the same parameter name more than once in a query, even if it will have the same value. You must use two parameters, and give them the same value, if that’s what you need.

It worked!
Thanks for your advise!