Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

php - MYSQLI::prepare() , error when used placeholder :something

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...