php - Do PDO tokens need to match the bindValue 1:1? -


i have code

$query = 'insert table                   (foo, bar, baz)                   values                   (:foo, :bar, :baz)           on duplicate key update foo = :foo,                                   bar = :bar,                                   baz = :baz'; $stmt = $dbc->prepare($query); $stmt->bindvalue(':foo', $foo, pdo::param_str); $stmt->bindvalue(':bar', $bar, pdo::param_str); $stmt->bindvalue(':baz', $baz, pdo::param_str);  $stmt->execute(); 

its throwing error:

fatal error: uncaught exception 'pdoexception' message 'sqlstate[hy093]: invalid parameter number: number of bound variables not match number of tokens

obviously, have twice many token bound variables, have same number of unique tokens. question is, can each token used once? need rename second instance of each token work, or there way without doubling bindvalue statements?

it turns out can reuse tokens. error else entirely. if find in future wondering same thing, yes it's possible. error else. missed colon or in mess of tokens forgot add bindvalue one.

as noted barmar below, functionality may need pdo::attr_emulate_prepares enabled occur. use mysql has enabled default, can not speak truth of off top of head.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -