當我在不支持get_result()的服務器上執行以下代碼時,$ results返回爲'1'。看來$ stmt-> fetch()不能正常工作。有什麼我做錯了嗎?PHP MySQLi準備語句fetch()返回'1'而不是查詢結果
我使用GoDaddy Shared Hosting帳戶和我的本地服務器作爲我的測試環境。我的本地服務器支持get_result(),以便按預期工作。
$stmt = self::$conn->prepare($sql);
$ex = $stmt->execute();
$stmt->store_result();
if (method_exists($stmt, 'get_result'))
{
$results = $stmt->get_result();
}
else
{
$results = $stmt->fetch();
}
是它的一個int(1)還是別的嗎?如果你想要一個關聯數組,你應該像傳遞$ stmt-> fetch(PDO :: FETCH_ASSOC) – user602525
一樣傳遞fetch_style。var_dump返回BOOL(true)。另外,$ stmt-> fetch()不接受參數。 –
哦,我的壞,我認爲這是PDO :: fetch() – user602525