Jump to content

Archived

This topic is now archived and is closed to further replies.

hvle

mysql_num_rows() failed hopelessly

Recommended Posts

mysql_num_rows() has strangely failed in Window platform.

well, I have this code

Line 1: $sql = "select ......";
Line 2: $rs = mysql_query($sql);
Line 3: $rowcount = mysql_num_rows($rs);
Line 4: somecode here
very basic and it works fine in Linux system my host server
however, in my local system (Windows) it failed every time $rs is empty.

What happened is if $rs returned a non-empty set, $rowcount will contain number of rows in that $rs and proceed to Line 4.
When a select statement that returned an empty set, the script just halt (simply stop and exit) right at
Line 3;

I have read the PHP documentation on mysql_num_rows() and it does not state any platform incompatiblity regarding this function. I hope somebody with more experiences would explain why it behaved this way.

Thanks a million.

Share this post


Link to post
Share on other sites
You probably should do something to check if the result set for your query is correct (if there is no sql-error, that is):
[code]
$sql="select * from employees";
$res=@mysql_query($sql);
if($res!=FALSE)
{
    echo mysql_num_rows($res);
}
else
{
    echo "There was an error in your SQL query: " . mysql_error() . "\n<br />The given SQL query was: " . $sql;
}[/code]

Share this post


Link to post
Share on other sites
Thanks for all replies,

After a lot of testing, i found the error on another module. The problem is not mysql_num_rows

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.