dousao2186 2014-04-05 20:36
浏览 311

某些查询出现PDO / MySQL错误(SQLSTATE [HY000])

In this snip-it of PHP code, I'm trying to access my database (dbconn is already defined)

public function get($statement) {
    echo $statement . '<br/>';
    $fetch = $this->dbconn->prepare($statement);
    $fetch->execute();
    $res = $fetch->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP);
    return $res;
}

Some example outputs of the whole program are, with the query = "example1"

SELECT * FROM keywords WHERE 1
SELECT bin FROM bins WHERE place LIKE 'example1'
{"centralLat":0,"centralLon":0,"errors":[],"posts":[],"location":"example1"}

The code returns the intersection of posts a location (that has been hashed out into bins on a map) and the keywords. The code works fine, it does interpretation on the string and does the appropriate querys, finds intersections, yadda yadda. The problem is for some queries, PDO fails to execute the query

in this case of query = "example2"

SELECT * FROM keywords WHERE 1
SELECT bin FROM bins WHERE place LIKE 'example2'  (this the the query that errors)

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: Invalid column index'

In the actual cases, it seems to consistently throw out these errors on SOME queries, but not all. For example: it will always run example1 successfully, but never run example2 successfully. But if I run either of the querys on phpMyAdmin, I cannot replicate the errors, and get the desired results.

The only notable difference, between example1 (and the like) and example2 (and the like) is that querys that work are LONGER (40+ characters), while queries that fail are SHORTER (39-)

Im not sure whats causing this error, any help would be appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料