Page 1 of 1

mysqli_stmt_num_rows returning 0 on 0 rows and 1 row

Posted: Fri Dec 15, 2006 7:05 pm
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?

Posted: Fri Dec 15, 2006 8:46 pm
by Begby
Try it with just execute(), store_result(), followed by num_rows. Comment out bind_results() and fetch(). See if that works.

Posted: Fri Dec 15, 2006 9:00 pm
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.