我刚刚开始使用 PDO,并在几个教程中查找了答案,但我无法让它工作。
我有
Notice: Undefined property: PDOStatement::$fetch in E:\-------- on line 22 
Result: 1
和
$dsn = "mysql:host=localhost;dbname=the_database;";
try {
    $dbh = new PDO($dsn, "root", "");
    $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch (PDOException $e){
    die( "failed conexion: ".$e->getMessage() );
}
$query = "SELECT MAX(price) AS max, MIN(price) AS min FROM cellphones";
try {
    $sth = $dbh->prepare($query);
    $sth->execute();
    $sth->setFetchMode(PDO::FETCH_ASSOC);
    $result = $sth->fetchAll;
    }
catch(PDOException $e){
    echo $e->getMessage();
    }
die( "<br />Result: ".print_r($result, true) );
我得到相同的结果
$sth = $dbh->query($query);
$result = $sth->fetchAll;
和
$sth = $dbh->prepare($query);
$sth->execute();
$result = $sth->fetch;
我得到的是它可能会返回结果计数但是为什么呢?以及为什么它给我一个关于 fetch / fetchAll 甚至没有声明的通知。我也没有任何例外。