Jump to content

mysql_num_rows() failed hopelessly


hvle

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.
Link to comment
https://forums.phpfreaks.com/topic/8610-mysql_num_rows-failed-hopelessly/
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]

Archived

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

×
×
  • Create New...

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.