本文介紹了mysqli 準(zhǔn)備語(yǔ)句中帶有 fetch_array 的 SELECT 語(yǔ)句的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我總是發(fā)現(xiàn)編寫 MySQLi 準(zhǔn)備好的語(yǔ)句很困難,因?yàn)樵S多函數(shù)的工作方式與舊方式不同.現(xiàn)在我正面臨一個(gè)關(guān)于 fetch_array()
的問(wèn)題.
I always find it difficult to write MySQLi prepared statements, because many functions work differently than in the old way. Right now I am facing a problem regarding fetch_array()
.
$stmt = $db->prepare("SELECT category_id FROM post_items Where user_id = ?");
$stmt->bind_param('i', $userid);
$result = $stmt->execute();
while ($row = $result->fetch_array()) {
// ...
}
推薦答案
您正在嘗試通過(guò)
$result = $stmt->execute();
事實(shí)并非如此.因?yàn)?execute 只會(huì)返回一個(gè)布爾值.
which is not the case. as execute will return you only a boolean value.
喜歡就好.
$stmt = $db->prepare("SELECT category_id FROM post_items Where user_id = ?");
$stmt->bind_param('i', $userid);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
//result is in row
}
這篇關(guān)于mysqli 準(zhǔn)備語(yǔ)句中帶有 fetch_array 的 SELECT 語(yǔ)句的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!