You are here:  » Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in includes/database.php

Support Forum



Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in includes/database.php

Submitted by marco@flapper on Wed, 2011-06-22 08:22 in

Hi,
I try to import some feeds. The large feeds get these warnings. I noticed it with feeds of 305K and 105K articles. The other smaller feeds didn't have any problems.

It looks like the issue in topic:
http://www.pricetapestry.com/node/203

So I dropped the products table. And made the changes to database.php and these show:
FAILED [MySQL server has gone away]

What is causing this ?

Submitted by support on Wed, 2011-06-22 11:09

Hi Marco,

MySQL server has gone away is an obscure problem but I think you had a similar issue with another table - http://www.pricetapestry.com/node/4040. Your host running a myisamchk against the products table appeared to resolve the issue that time. This should have a similar result to running REPAIR TABLE, so one thing to try would be to create a repair.php script as follows:

<?php
  set_time_limit
(0);
  require(
"includes/common.php");
  
$sql "REPAIR TABLE `".$config_databaseTablePrefix."products`";
  
database_queryModify($sql,$result);
  print 
"Done":
?>

Upload and browse to from the main Price Tapestry installation folder of the installation causing the problem and fingers crossed that should do the trick - if not of course, perhaps asking your host to run the same process will do the trick.

A second option that has successfully resolved "MySQL Server has Gone Away" for other users is to add a call to mysql_ping() in includes/database.php. To try this, look for the following code at line 47:

    $link = @mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);

...and REPLACE with:

    $link = @mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
    if (!mysql_ping($link))
    {
      @mysql_close($link); @mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword,TRUE);
    }

Hope this helps,

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Thu, 2011-06-23 07:07

I did all above but the error remains.

My host also checked the mysql server config and wait_timeout=60.

They refer to the code and this link:
http://www.phpfreaks.com/forums/index.php?topic=245848.0

Submitted by support on Thu, 2011-06-23 09:21

Hi Marco,

Whilst the server issue remains, you can resolve it by using a new database connection for every query. I would recommend starting with a clean includes/database.php from the distribution, then look for the following code at line 60:

    return mysql_affected_rows();

...and REPLACE with:

    $retval = mysql_affected_rows();
    mysql_close($link);
    return $retval;

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Fri, 2011-06-24 07:24

Hi,
I'm using the workaround now. But I guess it has an impact on the system load. What could I check more on the server?

I allready removed the database and ran setup again, but I still have the problem.

Submitted by support on Fri, 2011-06-24 08:24

Hi Marco,

Whilst the workaround will slow down the import process slightly it shouldn't really impact on server load at all as it's not doing anything particularly processor intensive during the additional connect / disconnect processes. However if there is a general server load issue during import the best approach is generally the 1 second sleep every 100 products or so, described in this thread - that would be the best thing to do if there is a load issue...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Fri, 2011-09-23 12:34

Hi,
I discovered something interesting while I was setting up a new PT website.

I got the Warning again: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in includes/database.php.

So I followed the actions in the thread. But while doing so I noticed that the error is not there in another modified PT code. I have the latest PT code in one folder and was testing it with the code which has some modifications to it. Both go to the same database. So probably the warning can be code related?

Submitted by support on Sun, 2011-09-25 16:59

Hi Marco,

That's interesting - first of all to confirm that it is the same issue could you enable database debug mode on the /ptbackup/ installation (as described above) and if it is still "MySQL Server Has Gone Away" if you could email me search.php from each installation (rename them to indicate which is which) I'll take a look at what the difference might be...

Thanks.
David.
--
PriceTapestry.com

Submitted by marco@flapper on Mon, 2011-09-26 07:04

Sorry, I forgot that I implemented the workaround in includes/database.php so that it is logical that the modified PT doesn't have the "MySQL Server Has Gone Away" problem.

Submitted by marco@flapper on Sat, 2011-10-01 19:52

Hi,
I had another MYSQL gone away problem and implemented the workarounds on that website too. But the problem didn't go away. After I dropped the database and did the setup again the problem was gone. I removed the workarounds and it is still working.

My host gave me the following as input:
"Its look like this issue caused due to mysql query syntax or may be due to accessing an empty record set resulted from any mysql query. Please check this with a coder inorder to prevent this issue in future."

Is this usefull?

Submitted by support on Sun, 2011-10-02 08:50

Thanks for that, Marco - it will be useful if I come across a repeatable instance of the problem in the future. There is very little information about this particular MySQL error on the web as if the reasons for it to happen are not necessarily the same every time; but some installations (combination of PHP / MySQL) may be more prone that others depending on version; underlying libraries etc...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Sun, 2011-10-02 20:36

I had it a couple of times now. During that time I had other PT installations on the same server without the error. This time just dropping the database and running the setup again solved. The time before I also needed a myisamcheck.

If I come across this error again I would go for to fix my website fast, but what would be helpfull for you to get more information on this problem?

Submitted by support on Mon, 2011-10-03 07:09

Hi marco,

Getting your site back online is the priority but if you could capture the error messages with database debug mode enabled for me so that the SQL is displayed that will show me which query / part of the code is being executed when the "MySQL Server Has Gone Away" problem occurs...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Sun, 2012-02-05 12:23

Hi,
I send you a email with the error messages.

Submitted by support on Sun, 2012-02-05 14:14

Thanks Marco I'll follow up by email;

Cheers,
David.
--
PriceTapestry.com