我想从 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()它将行作为用数据库表字段索引的数组返回
输出数组看起来像这样
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/