本文介紹了將 mysql_fetch_array 轉(zhuǎn)換為 PDO::FETCH_NUM的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
這兩個(gè)代碼在PDO中的等價(jià)物是什么
What is the equivalent of these two code in PDO
第一:
$row=mysql_fetch_array($query);
第二個(gè):
while($row=mysql_fetch_array($query)){
$data[]=$row;
}
我在下面使用了這些代碼,但我猜它們并不完全相同,因?yàn)槠溆嗟拇a不起作用.
i used these codes below but they are not exact same i guess, because the rest of the code didn't work.
$row = $query->fetch(PDO::FETCH_NUM);
和
$data[] = $query->fetch(PDO::FETCH_ASSOC);
推薦答案
對應(yīng)關(guān)系如下:
mysql_fetch_array
=fetch(PDO::FETCH_BOTH)
- 行是具有數(shù)字索引和命名索引的數(shù)組.mysql_fetch_assoc
=fetch(PDO::FETCH_ASSOC)
- 行是具有命名索引的數(shù)組.mysql_fetch_row
=fetch(PDO::FETCH_NUM)
- 行是帶有數(shù)字索引的數(shù)組.mysql_fetch_object
=fetch(PDO::FETCH_OBJ)
或fetch(PDO::FETCH_CLASS)
取決于您是否指定了可選的mysql_fetch_object
的 >className 參數(shù).行是指定類或stdClass
的對象.
mysql_fetch_array
=fetch(PDO::FETCH_BOTH)
- The rows are arrays with both numeric and named indexes.mysql_fetch_assoc
=fetch(PDO::FETCH_ASSOC)
- The rows are arrays with named indexes.mysql_fetch_row
=fetch(PDO::FETCH_NUM)
- The rows are arrays with numeric indexes.mysql_fetch_object
=fetch(PDO::FETCH_OBJ)
orfetch(PDO::FETCH_CLASS)
depending on whether you specify the optionalclassName
argument tomysql_fetch_object
. The rows are objects, either of the specified class orstdClass
.
while
循環(huán)相當(dāng)于:
$data = $query->fetchAll(PDO::FETCH_BOTH)
這篇關(guān)于將 mysql_fetch_array 轉(zhuǎn)換為 PDO::FETCH_NUM的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!