|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15417 occasioanlly no result returned
Submitted: 2002-02-06 21:04 UTC Modified: 2002-02-07 14:20 UTC
From: thorr at asenacorp dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.1.1 OS: Debian Linux 2.4.10
Private report: No CVE-ID: None
 [2002-02-06 21:04 UTC] thorr at asenacorp dot com
We moved our server from FreeBSD/PHP 4.0.6/Apache 1.3.20 to Debian/PHP 4.1.1/Apache 1.3.22. Now we are occasionally receiving the following warning for mysql_num_rows:

PHP Warning:  6 is not a valid MySQL result resource in /usr/local/webhosts/default/test.php on line 40

sometimes number 6 changes to 25, 38 etc. I could not figure out under which conditions it happens as most of the time when page is refreshed it disappears. It happens on many pages and probability of having warning increases as number of queries in the page increases. When that warning received there are no other errors or warnings. Also there is no result assosciated for the recordset that mysql_num_rows using although there should be and other recordsets are working fine.

I tried to reproduce the error with the following script and I managed to get a bunch of them. Approximately I got 9 warnings for 100 execution of the script. All executions are identical and warnings seemed to happen randomly.

Here is the script that I used for testing. The query returns 3 rows normally:

$dbHost = "";
$dbUser = "phpuser";
$dbPass = "passwd";
$dbName = "sb";

//Server Connection
if(!($dbLink = mysql_pconnect($dbHost,$dbUser,$dbPass)))
print("Failed to connect to database!<BR>\n");

//select database
print("Can't use database!<BR>\n");
	$qryCompare = "SELECT * FROM sb_Compare WHERE constant = 11 AND variant = 10;";
	if(!($recCompare=mysql_query($qryCompare, $dbLink)))
	  print("Query error!...<BR>\n");
	  print("MySQL say : " . mysql_error() . "<BR>\n");
	  print("Query was : $qryCompare<BR>\n");

	$qryCompar = "SELECT * FROM sb_Compare WHERE constant = 11 AND variant = 10;";
	if(!($recCompar=mysql_query($qryCompar, $dbLink)))
	  print("Query error!...<BR>\n");
	  print("MySQL say : " . mysql_error() . "<BR>\n");
	  print("Query was : $qryCompar<BR>\n");

	echo mysql_num_rows($recCompare);
	echo mysql_num_rows($recCompar);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-07 01:40 UTC]
I don't see any real reason for these failures, but I do see spurious semi-colons in your queries.  You should not be sending a semi-colon to terminate a query when sending it through mysql_query()
 [2002-02-07 11:07 UTC] thorr at asenacorp dot com
I never had problems with semi-colons at the end of queries. But neverthles I removed semi-colons and tried again. The result was the same. For 10 execution I got two errors:

[07-Feb-2002 09:52:21] PHP Warning:  34 is not a valid MySQL result resource in /usr/local/webhosts/ on line 37
[07-Feb-2002 09:52:48] PHP Warning:  34 is not a valid MySQL result resource in /usr/local/webhosts/ on line 37

I wonder why the error message contains specific number but not "supplied argument"?
 [2002-02-07 11:19 UTC]
My hitch is that you're running out of mysql connections for some reason... add this and check it:
mysql_connect() or die ("error");

of course use the normal mysql_connect function (with all parameters).

 [2002-02-07 11:27 UTC] thorr at asenacorp dot com
In fact I got many 'Got an error reading communication
 packets' errors on MySQL Server (like 5 errs / hour). I thought that, but shouldn't it give an error on mysql_query? Does mysql_num_rows requires connection to MySQL server or does it use recordset in memory?
 [2002-02-07 11:48 UTC] thorr at asenacorp dot com

It seems that you're right. I changed mysql_pconnect to mysql_connect and used mysql_close at the end of script. I got no error for 100 execution. 

I remember a similar problem that I read in somewhere about persistent connections. But i could not find it. But I am sure that I did not have this problem on previous configuration. Should I close this bugreport and reopen for pconnect or leave it? 
 [2002-02-07 13:51 UTC]
Well, it isn't a bug at all actually. pconnects need one connection to MySQL per Apache child / User Id.
You can either limit your apache children, or increase the maximum number of connections that MySQL allows.
I'm marking this as bogus now, as it's more a configuration issue then a real bug.

 [2002-02-07 14:20 UTC] thorr at asenacorp dot com
MaxClients 250

Mysql server variables:
max_connections 400

This is my current configuration. And I also checked number of processes on https server and mysql server when I got the error. http server had apprx 10 active and 20 idle servers and mysql server have ~15 processes.

Everything seems fine to me. Is that a configuration problem?
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Mar 22 22:03:41 2023 UTC