Simple question. lets say I run the following:
$results = mysql_query("SELECT * FROM table");
How can I load the mysql results array into a PHP array without doing a while loop? Example:
$mysql_results = array();
$results = mysql_query("SELECT * FROM table");
$mysql_results = mysql_load_all_results_into_array($results);
Thanks!
PHP’s
mysql_library does not offer a method to “fetch all” rows without looping through the results-object usingmysql_fetch_row()(or similar).You can, however, update your code to use the
mysqlilibrary which contains a method namedmysqli_result::fetch_allto perform the task you desire. Alternatively, you could update to usePDOwhich contains a similar method namedPDOStatement::fetchAll.As the
mysql_methods are being deprecated, updating tomysqli(orPDO) is the recommended way to go regardless.