PHP hangs with empty result set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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);


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux