我想从MySQL数据库中检索一行,该数据库返回一行,例如,带有相应键的行。现在,检索一行只会在打印时以PHP格式给出一个数组:
Array
(
[0] => 15
[1] => 2011-02-27 22:31:46
[2] => salmon-with-pineapple-curry-sauce-photo_0.jpg
[3] => 1
[4] => Salmon Fillet
[5] => Trader Joes
[6] => So delicious
[7] => 5
[8] => 35.282753
[9] => -120.659615
)
如何检索,以便密钥是数据库中字段的名称,以便在使用json_encode函数时,密钥与值相关联?
最佳答案
看看mysql_fetch_assoc()它将行作为一个用DB table field索引的数组返回
输出数组将如下所示
Array
(
['id'] => 15
['date'] => 2011-02-27 22:31:46
['name'] => salmon-with-pineapple-curry-sauce-photo_0.jpg
.....
.....//other elements or fields
)
关于php - 检索MySQL行键,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5139276/