简体   繁体   English

PDO_MYSQL:一般错误 2014

[英]PDO_MYSQL: general error 2014

I'm migrating from plain mysql_* to PDO (yeah, I know it's 2012 on the calendar).我正在从普通的 mysql_* 迁移到 PDO(是的,我知道日历上是 2012 年)。
I'm writing a simple wrapper class to have an opportunity to do things like $f=$db->FetchAll("SELECT * FROM...") on my website.我正在编写一个简单的包装类,以便有机会在我的网站上执行诸如 $f=$db->FetchAll("SELECT * FROM...") 之类的操作。 Here's what I'm doing:这是我在做什么:

    public function Query($q, $errmessage="", $params=array()) {
    try {
    $stmt=$this->connect->prepare($q);
    if (is_array($params) && count($params)>0) {
    $stmt->execute($params);
    } else {
    $stmt->execute();
    }
    return $stmt;
    } catch(PDOException $e) {
    die($errmessage.": ".$e->GetMessage());
    }
    }

   public function Fetch($q, $arraylist=0) {
    if (!is_object($q)) { // Assuming it's a raw query
    $stmt=$this->Query($q, "Unable to process the query for fetching");
    } else $result=$q;
    $f=$stmt->Fetch();
    return $f;
}

And this throws a "general error 2014" exception.这会引发“2014 年一般错误”异常。
Any help appreciated.任何帮助表示赞赏。
Thanks!谢谢!

2014 isn't a year, it's an error code. 2014不是一年,而是一个错误代码。 Try googling the error next time.下次尝试谷歌搜索错误

$pdo->query("INSERT INTO test (some) VALUES ('1111111111111111'), ('1111111111111'); -- I AM AN SQL COMMENT, REMOVING ME WILL SOLVE THIS PROBLEM"); $pdo->query("INSERT INTO test (some) VALUES ('1111111111111111'), ('1111111111111'); -- 我是一条 SQL 评论,删除我将解决这个问题");

Due to the ";"因为 ”;” this is a multi-statement, executing two queries while the second is only a comment.这是一个多语句,执行两个查询,而第二个只是一个注释。 The second "result" can be accessed using PDOStatement->nextRowset.可以使用 PDOStatement->nextRowset 访问第二个“结果”。 [source] [来源]

or:或者:

After spending hours trying to track down why we were getting this error on a new server, after the same code ran fine on other servers, we found the problem to be an old MySQL client library running on our web server, and a latest-version MySQL server running on the database server's box.在花了几个小时试图追查为什么我们在新服务器上收到此错误之后,在相同的代码在其他服务器上运行良好之后,我们发现问题出在我们的 Web 服务器上运行的旧 MySQL客户端库和最新版本MySQL服务器运行在数据库服务器的机器上。 [source] [来源]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM