获取所有MySQL选定的行到一个数组 [英] Get all mysql selected rows into an array
本文介绍了获取所有MySQL选定的行到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有在PHP函数,可以让我把我所有的选择的数据在阵列中。目前我使用mysql_fetch_array正如我在手册中已阅读,该功能将不会在表中提取每一条记录
$结果= mysql_query(SELECT * FROM $ tableName值);
$阵列= mysql_fetch_array($结果); 回声json_en code($数组);
解决方案
我会建议对性能和安全的使用库MySQLi或MySQL PDO,但是要回答这个问题:
而($行= mysql_fetch_assoc($结果)){
$ json的[] = $行;
}回声json_en code($ JSON);
如果您切换到mysqli的你可以这样做:
$ JSON = mysqli_fetch_all($结果,MYSQLI_ASSOC);
回声json_en code($ JSON);
I am wondering if there a function in php that can allow me put all my selected data in an array .Currently i am using mysql_fetch_array and as i have read in the manual,that function won't fetch every record in the table.
$result = mysql_query("SELECT * FROM $tableName");
$array = mysql_fetch_array($result);
echo json_encode($array);
解决方案
I would suggest the use of MySQLi or MySQL PDO for performance and security purposes, but to answer the question:
while($row = mysql_fetch_assoc($result)){
$json[] = $row;
}
echo json_encode($json);
If you switched to MySQLi you could do:
$json = mysqli_fetch_all ($result, MYSQLI_ASSOC);
echo json_encode($json );
这篇关于获取所有MySQL选定的行到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文