如何将 sql 对象转换为多维数组


How to convert a sql object into a multidimensional array?

我写了这个简单的代码,我从MySQL表中提取了两列。然后我无法将其转换为多维数组。

所以我的表只有 2 行,我期望它会给我 2 行和 2 列的输出。但相反,数组大小为 4(而不是 2(,而且它给出了temp[2]temp[3]打印错误

<?php 
mysql_connect("localhost","root",""); //Connecting to the localhost
mysql_select_db("user"); //Selecting a database
$auth_data = mysql_query("SELECT EMAIL,UNIQUE_ID FROM authentication"); 
#Converting the object to an array
$temp = mysql_fetch_array($auth_data, MYSQL_BOTH);
echo sizeOf($temp);
echo $temp[0];
echo $temp[1];
echo $temp[2];
echo $temp[3];
?>

错误:

4abhinav.chawla@iiitb.org1
Notice: Undefined offset: 2 in C:'xampp'htdocs'test'test.php on line 11
Notice: Undefined offset: 3 in C:'xampp'htdocs'test'test.php on line 12

你正在使用 MYSQL_BOTH ,所以你把数字和字符串键都放进$temp,它只保存你的查询的第一个结果

请使用PDO/mysqli并请放下mysql_*

 you selected only two fields  so output will be two parameter.
> select emailadn uniqueid from tablename. parameter $temp[0]; $temp [1]
> ..................... $temp[2] $temp[3] wrong array