PDO bindParam() with multiple named parameters

▼魔方 西西 提交于 2019-12-01 17:11:49

问题


Can't PDO bind a value to multiple occurrences of a param in a query with a single bindParam()?

I'm surprised, I thought it was possible, but I didn't find any info on php's docs on this, neither on the web. Any clarification / alternative is welcome!

Note : I'm using php 5.3.6 / 5.3.8 (dev/prod)


Example :

Consider this prepared statement :

INSERT INTO table VALUES (:param1, 0), (:param1, 1);

Now, if I bind values to my query:

bindParam(":param1",$my_param1);

I have a PDO error :

SQLSTATE[HY093]: Invalid parameter number


回答1:


See PDO::prepare

You cannot use a named parameter marker of the same name twice in a prepared statement


来源:https://stackoverflow.com/questions/21777516/pdo-bindparam-with-multiple-named-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!