[PHP-BUG] Bug #51493 [NEW]: $result->num_rows return wrong

[email protected] ("zhuzhixiong at hotmail dot com") Wed, 7 Apr 2010 11:06:31 +0200 (CEST)
Newsgroups php.bugs
Message-ID <[email protected]>
From:             
Operating system: window xp sp2
PHP version:      5.2.13
Package:          MySQLi related
Bug Type:         Bug
Bug description:$result->num_rows return wrong

Description:
------------
mysql version is 5.1.45-community
when I use the script below,$result->num_rows return 0;(it is supported to
return 1;I echo the sql,and execute it in mysql client,and return 1
result)
if I change sql to "select `id` from mobile_breed",$result->num_rows return
the right numbers

Test script:
---------------
<?php
function getBreedId($breed_name,$handle)
{
	$handle = new mysqli("localhost","root","123456","wjtx");
	$sql = "select `id` from mobile_breed where `breed_name`='".$breed_name."'
limit 0,1";
	$result = $handle->query($sql);
	if(!$result)
	{
		return false;
	}
	else
	{
                $num = $result->num_rows();
		if($num==0)
		{
			return false;
		}
		else
		{
			$row = $result->fetch_assoc();
			return $row['id'];
		}
	}
}
echo getBreedId("nokia",'5230');
?>

Expected result:
----------------
return an id;

Actual result:
--------------
return false;
because $result->num_rows return 0,so returned fasle;

-- 
Edit bug report at http://bugs.php.net/bug.php?id=51493&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=51493&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=51493&r=trysnapshot53
Try a snapshot (PHP 6.0):            http://bugs.php.net/fix.php?id=51493&r=trysnapshot60
Fixed in SVN:                        http://bugs.php.net/fix.php?id=51493&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51493&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=51493&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=51493&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=51493&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=51493&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=51493&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=51493&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=51493&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=51493&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=51493&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51493&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51493&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=51493&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=51493&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=51493&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=51493&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=51493&r=mysqlcfg