mysqli_stmt_num_rows returning 0 on 0 rows and 1 row

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Cody Mays
Forum Newbie
Posts: 10
Joined: Fri Dec 15, 2006 3:01 pm

mysqli_stmt_num_rows returning 0 on 0 rows and 1 row

Post by Cody Mays »

Hi,
I'm currently having issues with mysql_stmt_num_rows returning both 0 rows on 0 rows, and 0 rows on 1 valid row. Am I doing something wrong or is this a bug that should be reported?

Here is a sample of what I'm doing:

Code: Select all

if($stmt = $db->prepare("SELECT id, queries FROM ".STATS_TABLE." WHERE date = ? and id = ?"))
		{
			$stmt->bind_param('si', $date, $this->id);
			$stmt->execute();
			
			/* Get the results */
			$stmt->bind_result($id, $query_count);
			$stmt->fetch();
			$stmt->store_result();
			
			/* $stmt->num_rows is an alias for mysqli_stmt_num_rows() */
			echo($stmt->num_rows.'-'.$api_id);
		}
Now, in the table for this simple query, if there is no valid row with the correct date, I get 0 rows. If there is a row with a valid date, I get 0 rows. Any ideas?
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Try it with just execute(), store_result(), followed by num_rows. Comment out bind_results() and fetch(). See if that works.
Cody Mays
Forum Newbie
Posts: 10
Joined: Fri Dec 15, 2006 3:01 pm

Post by Cody Mays »

I guess the key here would be to run $stmt->fetch() after checking to see if there are any valid rows? That did seem to work, but it just doesn't seem as logical as the old way most people used mysql_num_rows.
Post Reply