我一直收到这个错误,但我不知道为什么......
错误是:
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
我的查询是这样的:
$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
}
脚本可以正常运行,但无论如何都会显示错误= /
错误是什么意思,我该如何解决?
答案 0 :(得分:0)
那是因为你必须在try
语句中运行while循环:
try {
$stmt->execute();
while($row = $stmt->fetch()){
//do stuff
}
}
catch (PDOException $e) {
echo $e -> getMessage();
}
您看到此消息是因为您的查询有问题。尝试:
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