简体   繁体   中英

PDO: Invalid parameter number

I'm making an IS and I have a problem with updating mysql table. I'm using PHP 5.3 and PDO.

            $query_update = $this->db_connection->prepare('UPDATE Client SET name =: name, surname=:surname WHERE id=:id');
            $query_update->bindValue(':id', $id, PDO::PARAM_INT);
            $query_update->bindValue(':name', $name, PDO::PARAM_STR);
            $query_update->bindValue(':surname', $surname, PDO::PARAM_STR);
            $query_update->execute();

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in file on line X. The Warning is referencing line with execute().

Thanks for help.

EDIT: It's working now, again thanks for help.

You have a space too much. Correct you query to this:

$this->db_connection->prepare('UPDATE Client SET name =:name, surname=:surname WHERE id=:id');
// -----------------------------------------------------^

This lead to only two variables being used in the query, which didn't match the 3 variables you provided.

(Your query in the current form should throw an error anyways at the same position.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM