PHP hangs with empty result set

From: Date: Wed, 23 Mar 2011 19:34:34 +0000
Subject: PHP hangs with empty result set
Groups: php.general 
Request: Send a blank email to php-general+get-312017@lists.php.net to get a copy of this message
I've been having a problem when querying a database with php and the mysql library  the offending code follows.  If the result is an empty set, PHP hangs.  I've had to add code to the script to set up a max execution time to kill the script after 30 seconds if it doesn't complete.  This is happening on a very busy site and in the past, it has brought the server to its knees.  The code that follows is actual code copied and pasted from the script.  I've trie wrapping an "if ($result_2) {...}: and "if (mysql_num_rows($result_2) > 0) { ..}" around the while loop and it's made no difference. thanks in advance, Curtis $dbhandle2 = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("database",$dbhandle2) or die("Could not select examples"); while ($_parent !="0") { $result_2 = mysql_query("SELECT catagory_parent FROM t_catagories where catagory_ID=" .$_parent); $num_rows_2 = mysql_num_rows($result_2); if($num_rows_2 > "0") { while ($row = mysql_fetch_array($result_2)) { $_parent= $row{'catagory_parent'}; $_parents[$counter] = $row{'catagory_parent'}; $counter++; } } } mysql_close($dbhandle2);

« previous php.general (#312017) next »