Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/oscommerce/includes/functions/database.php on line 99
Line 98-100 of my database.php file contained:
function tep_db_fetch_array($db_query) {
return mysql_fetch_array($db_query, MYSQL_ASSOC);
}
Clearly, somewhere in my code I had a call to tep_db_fetch_array, in which I was passing an invalid resource. The proper way to call tep_deb_fetch_array is to first prepare a select statement using tep_db_query, as shown below:
$my_select_statement = 'Select * from ' . TABLE_CATEGORIES;
$my_query = tep_db_query($my_select_statement);
while ($my_result_row = tep_db_fetch_array($my_query)) {
$my_cat_id = $my_result_row['categories_id'];
....
}
The function tep_db_query returns an resource of type 'mysql result'. If $my_query had been an invalid resource (eg not defined, or null, containing a string or numeric value, or containing anything at all other than a properly formed 'mysql result' resource), then it would have caused warning message I saw.
One way of testing your code is to call mysql_query directly, bypassing all the osc wrappers, like so:
$my_select_statement = 'Select * from ' . TABLE_CATEGORIES;
$qr1 = mysql_query ($my_select_statement)
or die ("Query failed: " . mysql_error() . " Actual query: " . $my_select_statement);
In my case, I got this warning message after making a mistake in installing Linda McGrath's very nice addon Attributes Sorter and Copier (http://www.oscommerce.com/community/contributions,772) version 5.1b. It concerned some tricky merging of code in the file catalog\admin\categories.php, tricky because I had already edited that section of code with other addons (Additional Images and New Attribute Manager). I had the line:
while ($new_images = tep_db_fetch_array($images_product)) {
But $images_product was undefined because I had overwritten the code that defined it.
The tricky section of code in file catalog\admin\categories.php started with:
default:
if ($rows > 0) {
if (isset($cInfo) && is_object($cInfo)) {
and ended with:
} else { // create category/product info
$heading[] = array('text' => '<b>' . EMPTY_CATEGORY . '</b>');
$contents[] = array('text' => TEXT_NO_CHILD_CATEGORIES_OR_PRODUCTS);
}
break;
}
By reinstalling this section of code from my backup, and then more carefully installing the Attributes Sorter and Copier addon, I was able to fix the problem.