問題描述
我使用 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.)
這篇關于MYSQLI::prepare() ,使用占位符時出錯:something的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!