我使用這個說法在我的分貝如何在php中使用fetchAll?
$result = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
獲取一列中的元素,但試圖運行它時,我得到這個錯誤。
調用未定義的方法mysqli_stmt::fetchAll();
有什麼我需要添加到我的PHP文件,包括方法還是什麼?
更新1:
class LoginAPI
{
private $db;
function __construct()
{
$this->db = new mysqli('xxx', 'xxx', 'xxx', 'xxx');
$this->db->autocommit(FALSE);
}
function __destruct()
{
$this->db->close();
}
function login()
{
if(isset($_POST["lang"]))
{
$stmt = $this->db->prepare("SELECT code FROM locations");
$stmt->execute();
$stmt->bind_result($code);
//while($stmt->fetch())
//{
// result[] = "code"=>$code;
// break;
//}
$codeArr = array();
$result = $stmt->fetch_all();//|PDO::FETCH_GROUP;
sendResponse(200, json_encode($result));
return true;
}
sendResponse(400, 'Invalid Request');
return false;
}
}
你正在使用'PDO'或'mysqli'?無論如何,你在這裏混合兩個。 – itachi
看起來像你的混合PDO和mysqli。如果你發佈了連接方式,它會顯示你正在創建一個mysqli連接對象,而不是PDO語句。 mysqli結果集對象具有fetch_all()而不是函數fetchAll()。 fetchAll()是PDOStatement類提供的一個函數。看到這個:http://php.net/manual/en/mysqli-result.fetch-all.php – Ray
請檢查http://us1.php.net/pdostatement.fetchall#refsect1-pdostatement.fetchall-examples – CodeTalk