PHP PDO编写的SELECT语句

时间:2012-09-07 11:37:25

标签: php pdo prepared-statement

我尝试在php中用PDO做一个准备好的SELECT语句。这是我的发言:

    # named placeholders 
    $STH = $DBH->("SELECT * FROM `highscore_ranked` WHERE DeviceID = :deviceid ORDER BY Points DESC LIMIT 0 , 10");
    $STH->bindValue(':deviceid', $DeviceIDClear);

    # setting the fetch mode
    $STH->setFetchMode(PDO::FETCH_ASSOC);
    $STH->execute();

但是我得到了错误:

 PHP Parse error:  syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '{' or '$'

在这一行:

 $STH = $DBH->("SELECT * FROM `highscore_ranked` WHERE DeviceID = :deviceid ORDER BY Points DESC LIMIT 0 , 10");

我不知道这条线路有什么问题。

1 个答案:

答案 0 :(得分:3)

你忘了方法的名字!!!!

$STH = $DBH->prepare("SELECT * FROM `highscore_ranked` WHERE DeviceID = :deviceid ORDER BY Points DESC LIMIT 0 , 10");