本文介紹了將 mysql_fetch_array 轉換為 PDO::FETCH_NUM的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
這兩個代碼在PDO中的等價物是什么
What is the equivalent of these two code in PDO
第一:
$row=mysql_fetch_array($query);
第二個:
while($row=mysql_fetch_array($query)){
$data[]=$row;
}
我在下面使用了這些代碼,但我猜它們并不完全相同,因為其余的代碼不起作用.
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);
推薦答案
對應關系如下:
mysql_fetch_array
=fetch(PDO::FETCH_BOTH)
- 行是具有數字索引和命名索引的數組.mysql_fetch_assoc
=fetch(PDO::FETCH_ASSOC)
- 行是具有命名索引的數組.mysql_fetch_row
=fetch(PDO::FETCH_NUM)
- 行是帶有數字索引的數組.mysql_fetch_object
=fetch(PDO::FETCH_OBJ)
或fetch(PDO::FETCH_CLASS)
取決于您是否指定了可選的mysql_fetch_object
的 >className 參數.行是指定類或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
循環相當于:
$data = $query->fetchAll(PDO::FETCH_BOTH)
這篇關于將 mysql_fetch_array 轉換為 PDO::FETCH_NUM的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!