How to export to an array a MySQL query with 3 lines of code
By reading a good contribution on PHP site, I discovered this method for exporting to an array a query submitted to MySQL:
$result = mysql_query("SELECT * FROM table");
for($i = 0; $array[$i] = mysql_fetch_assoc($result); $i++) ;
array_pop($array); // removes last empty array
It produces:
Array
(
[0] => Array
(
[id] => 1
[user] => myuser
[pass] => mypass
... other fields
)
... and so on
That’s to say you’ll have count($array) records, of which every row has count($array[0]) fields.