我有一个包含列的简单用户表:用户名、密码、电子邮件、姓名、姓氏、出生日期、地址和城市。前三个是强制性的,但其余的可以为空。我正在连接到数据库并获取数组中的行并打印它。
$dbc=mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$sql = "select * from user";
$data = mysqli_query($dbc, $sql) or die("query exec error");
//$json = array();
if(mysqli_num_rows($data)){
while($row=mysqli_fetch_array($data)){
//$json['Kullanici'][]=$row;
print_r($row);
echo "<br /><br />";
}
}
mysqli_close($dbc);
//echo json_encode($json);
但是输出是这样的:
Array ( [0] => ayse [username] => ayse [1] => b1b3773a05c0ed0176787a4f1574ff0075f7521e [password] => b1b3773a05c0ed0176787a4f1574ff0075f7521e [2] => ayse@hotmail.com [email] => ayse@hotmail.com [3] => [name] => [4] => [surname] => [5] => 0000-00-00 [birthdate] => 0000-00-00 [6] => [address] => [7] => istanbul [city] => istanbul )
Array ( [0] => baris [username] => baris [1] => 7c4a8d09ca3762af61e59520943dc26494f8941b [password] => 7c4a8d09ca3762af61e59520943dc26494f8941b [2] => bakkurt@hotmail.com [email] => bakkurt@hotmail.com [3] => Barış [name] => Barış [4] => [surname] => [5] => 0000-00-00 [birthdate] => 0000-00-00 [6] => [address] => [7] => [city] => )
问题是为什么同时存在 [0]=>baris 和 [username] => baris。我只期待用户名=> baris。我错了吗?我在哪里失踪?如果我解决了这个问题,我将通过删除注释将数组转换为 json。