本文介绍了使用PDO prepare和bindParam插入DB表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单来说,有人可以解释我在这里做错了什么吗?-我只是尝试使用prepare和bindParam插入数据库,这是将0和Null插入所有字段.
In simple terms can someone explain what I am doing wrong here - I am simply trying to insert into a db with with prepare and bindParam, this is inserting 0 and Null into all the fields.
$sql = $db->prepare("INSERT INTO db_fruit VALUES (id=? ,type=? ,colour=?)");
$sql->bindParam(1, $newId);
$sql->bindParam(2, $type);
$sql->bindParam(3, $colour);
$sql->execute()
btw:此方法对UPDATE等有效,但在这种情况下不适用于INSERT
btw: this method has been working for me for UPDATE etc, but not in this case for INSERT
推荐答案
您的语法不正确,请尝试以下操作:
Your syntax is incorrect, try this:
$sql = $db->prepare("INSERT INTO db_fruit (id, type, colour) VALUES (? ,? ,?)");
$sql->bindParam(1, $newId);
$sql->bindParam(2, $name);
$sql->bindParam(3, $colour);
$sql->execute();
这篇关于使用PDO prepare和bindParam插入DB表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!