Reputation: 8277
I keep getting this error but i don't know why....
The error is:
Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]:
General error' in test.php:25\nStack trace:\n#0 test.php(25):
PDOStatement->fetch()\n#1 {main}\n thrown in test.php on line 25
My query is like this:
$stmt = $pdo->prepare("
SELECT *,t1.id AS theID FROM users
t1 LEFT JOIN users_settings t2
ON t1.id=t2.tid
INNER JOIN extra_settings t3
ON t2.bid=t3.id");
try {
$stmt->execute();
} catch (PDOException $e) {
echo $e -> getMessage();
}
while($row = $stmt->fetch()){ //error is here
//do stuff
}
The script works but the error displays anyway =/
What does the error mean and how do i fix it ?
Upvotes: 1
Views: 1280
Reputation: 5165
That's because you have to run the while loop within the try
statement:
try {
$stmt->execute();
while($row = $stmt->fetch()){
//do stuff
}
}
catch (PDOException $e) {
echo $e -> getMessage();
}
You are seeing this message because there is something wrong with your query. Try:
SELECT *,t1.id AS theID FROM users
t1 LEFT JOIN t2.users_settings
ON t1.id=t2.tid
INNER JOIN t3.extra_settings
ON t2.bid=t3.id
Upvotes: 1