-1

这段代码工作正常:

$query = "SELECT * FROM user WHERE id = 1;";
$stmt = $this->openDb()->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

为什么此代码不起作用并给我错误Fatal error: Call to a member function fetchAll() on a non-object in

$result_set = $this->openDb()->prepare("SELECT * FROM user WHERE id = 1;")->execute()->fetchAll(PDO::FETCH_ASSOC);
4

1 回答 1

1

$stmt->execute(); 不返回对象,它返回一个布尔值。http://www.php.net/manual/de/mysqli-stmt.execute.php

于 2013-06-29T22:29:31.123 回答