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.