PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Tue Jun 12, 2012 4:01 am
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);
}
?>
Last edited by
social_experiment on Tue Jun 12, 2012 7:28 am, edited 1 time in total.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Tue Jun 12, 2012 6:23 am
What about var_dump($sql) one line above the fetch_object call? Is that returning mysqli_result like it should?
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Tue Jun 12, 2012 6:42 am
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;
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Tue Jun 12, 2012 7:28 am
Nm. The value i'm searching for seems to be missing from the database.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering