php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51493 $result->num_rows return wrong
Submitted: 2010-04-07 11:06 UTC Modified: 2010-04-07 11:33 UTC
From: zhuzhixiong at hotmail dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.2.13 OS: window xp sp2
Private report: No CVE-ID: None
 [2010-04-07 11:06 UTC] zhuzhixiong at hotmail dot com
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;

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-07 11:12 UTC] zhuzhixiong at hotmail dot com
-Status: Open +Status: Closed
 [2010-04-07 11:12 UTC] zhuzhixiong at hotmail dot com
Sorry for this.
It is my fault.
 [2010-04-07 11:33 UTC] pajoye@php.net
-Status: Closed +Status: Bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 02:01:29 2024 UTC