Jump to content

PDO Invalid parameter number: number of bound variables does not ma..


ttocskcaj

Recommended Posts

I'm new to using PDO and prepared statements. I have the following code:

            $db = MineCMS::get()->getDatabase();
            $stmt = $db->prepare("SELECT * FROM `` WHERE `?` = '?'");
            $result = $stmt->execute(array($db->prefix('servers'),$by,$value));
            $row = $result->fetch();

Where $db is an instance of PDO.

 

It returns the following error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

What am I doing wrong?

You should check out the examples in the manual.

 

For one, you've only defined 2 parameters, but attempt to use 3 in the execute method.

 

Another, you are trying to SELECT from... a table with an empty name?

 

Finally, you aren't supposed to have column/table names as parameters. It won't work properly. You shouldn't be defining those from insecure sources anyways.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.