MYSQLI::prepare() ,使用占位符时出错:something
我使用 mysqli,我看到了一些使用占位符的示例,例如 :something 和 ?p>
我什么时候用过?它的工作原理,但是当我使用 :something 这样的查询
<块引用>$sql = 插入食物(食物名称)值(:food_name)
然后当我打电话时出现错误
<块引用>$mysqli_object->prepare($sql);
错误信息听起来像这样
<块引用>用户错误!你有一个错误SQL 语法;检查手册对应于您的 MySQL 服务器使用正确语法的版本':food_name)' 附近
但是当我使用?作为占位符,一切正常,我使用 PHP 5.3.1 和 MySQL 5.1.41
我错过了什么地方,任何帮助将不胜感激,谢谢
解决方案mysqli 不支持命名占位符.
PDO 使用 bindParam
或 execute
.
(请注意,每个查询只能使用一次命名占位符.它们并不是非常有用.)
hi im using mysqli and i saw some examples using placeholder like :something and ?
when i used ? its working, but when i used :something in query like this
$sql = INSERT INTO food(food_name) VALUES(:food_name)
then error showed up when i called
$mysqli_object->prepare($sql);
error message sounds like this
User Error! You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':food_name)' at line
but when i used ? as the placeholder, everything working well, i used PHP 5.3.1 and MySQL 5.1.41
am i missed somewhere, any help will be appreciated thanks
解决方案mysqli does not support named placeholders.
PDO does, using either bindParam
or execute
.
(Careful, you can only use a named placeholder once per query. They aren't too incredibly useful.)
相关文章