PDO错误:一般错误:2031 [英] PDO error: General error: 2031

查看:122
本文介绍了PDO错误:一般错误: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:

如果dbconnectPDO的实例,则 query都会创建一个准备好的语句,然后一次性执行所有操作.因此,它最初没有获得参数绑定.使用 PDO::prepare 代替PDO::query.

If dbconnect is an instance of PDO then query both creates a prepared statement and then executes it all in one go. So its not getting the parameters bound initially. Use PDO::prepare instead of PDO::query.

这篇关于PDO错误:一般错误:2031的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆