1

我一直收到这个错误,但我不知道为什么......

错误是:

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
}

该脚本有效,但仍然显示错误=/

错误是什么意思,我该如何解决?

4

1 回答 1

1

那是因为您必须在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
于 2013-02-19T05:10:21.173 回答