Page 1 of 1

mysqli_fetch_object() issue [solved]

Posted: Tue Jun 12, 2012 4:01 am
by social_experiment
The code below is self-explanatory and the problem is that var_dump($obj) is returning NULL; database connection is ok, query is fine when i print it to the browser. The commented section where the mysqli_error() function returns no errors; i'm confused about where the issue is and would appreciate any ideas about possible causes. Thanks in advance.

Code: Select all

<?php
protected function _retrieveIndividualSurveyPId($subjectNum)
	{
		$subjectNum = trim($subjectNum);
		
		$query = "SELECT `parentsubjectid` FROM `is_table` WHERE 
		`subjectnum` = '" . mysqli_real_escape_string($this->_dbResource, 
		$subjectNum) . "' ";
		$sql = mysqli_query($this->_dbResource, $query);
		//
/*
$sql = mysqli_query($this->_dbResource, $query) or 
		die(mysqli_error($this->_dbResource));
*/
		
		$obj = mysqli_fetch_object($sql);
		
		var_dump($obj);		
	}
?>

Re: mysqli_fetch_object() issue

Posted: Tue Jun 12, 2012 6:23 am
by Celauran
What about var_dump($sql) one line above the fetch_object call? Is that returning mysqli_result like it should?

Re: mysqli_fetch_object() issue

Posted: Tue Jun 12, 2012 6:42 am
by social_experiment
It looks like it

Code: Select all

<?php
var_dump($sql);
// returns 
// object(mysqli_result)#4 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) } 
?>
Edit
If i use execute the code without the WHERE clause the problem disappears;

Re: mysqli_fetch_object() issue

Posted: Tue Jun 12, 2012 7:28 am
by social_experiment
Nm. The value i'm searching for seems to be missing from the database. :oops: