PDO错误:一般错误:2031 [英] PDO error: General error: 2031
问题描述
我在执行代码时收到此错误. 我知道这里已经讨论了几次,但是我无法通过阅读那里提供的解决方案来解决我的问题.
I get this error when i'm executing my code. I know this has been discussed a several times here but i couldn't solve my problem by reading the solutions provided there.
这是我得到的错误: 致命错误:消息为"SQLSTATE [HY000]"的未捕获异常"PDOException":常规错误:2031
This is the error i get: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2031
这是我的代码:
function insertMarker(){
$lat = $_POST['lat'];
$long = $_POST['long'];
$street = $_POST['street'];
$city = $_POST['city'];
$zip = $_POST['zip'];
echo ("$lat, $long, $street, $city, $zip");
global $dbconnect;
$query = $dbconnect->query("INSERT INTO address (latitude, longitude, street, city, zip) VALUES (?,?,?,?,?)");
$query->bindParam(1, $lat);
$query->bindParam(2, $long);
$query->bindParam(3, $street);
$query->bindParam(4, $city);
$query->bindParam(5, $zip);
$query->execute();
//$query->execute(array(":lat"=>$lat, ":long"=>$long,":street"=>$street,":city"=>$city,":zip"=>$zip));
}
推荐答案
只需将我的评论作为答案:
Just making my comment an answer:
如果
dbconnect
是PDO
的实例,则query
都会创建一个准备好的语句,然后一次性执行所有操作.因此,它最初没有获得参数绑定.使用PDO::prepare
代替PDO::query
.
If
dbconnect
is an instance ofPDO
thenquery
both creates a prepared statement and then executes it all in one go. So its not getting the parameters bound initially. UsePDO::prepare
instead ofPDO::query
.
这篇关于PDO错误:一般错误:2031的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!