在php中将mysql结果变量转换为多维数组的最简单方法是什么?

时间:2021-09-23 15:43:53

What is the easiest way to turn a mysql result variable into a multidimensional array in php?

在php中将mysql结果变量转换为多维数组的最简单方法是什么?

Thanks

2 个解决方案

#1


if you happen to be using the mysqli extension and php 5.3, you could use http://us2.php.net/manual/en/mysqli-result.fetch-all.php

如果你碰巧使用mysqli扩展和php 5.3,你可以使用http://us2.php.net/manual/en/mysqli-result.fetch-all.php

#2


Run mysql_fetch_assoc in a loop.

在循环中运行mysql_fetch_assoc。

while ($row = mysql_fetch_assoc($result)) {
    $table[] = $row;
}

print_r($table);

#1


if you happen to be using the mysqli extension and php 5.3, you could use http://us2.php.net/manual/en/mysqli-result.fetch-all.php

如果你碰巧使用mysqli扩展和php 5.3,你可以使用http://us2.php.net/manual/en/mysqli-result.fetch-all.php

#2


Run mysql_fetch_assoc in a loop.

在循环中运行mysql_fetch_assoc。

while ($row = mysql_fetch_assoc($result)) {
    $table[] = $row;
}

print_r($table);