Page 1 of 1

weird problem with mysqli

Posted: Thu Aug 06, 2009 12:33 am
by kjr
I have this piece of code:

Code: Select all

 
 
public function getEntry($uniqId,$pageNo){
 
  $mysqli=kjrDB::dbStart();
   
  $qry="SELECT entries.title,entries.body FROM entries JOIN details ON details.id=entries.id WHERE details.uniqID=? AND entries.page=?";
 
  if($stmt=$mysqli->prepare($qry)){
    $stmt->bind_param('si',$uniqId,$pageNo);
    $stmt->execute();
    $stmt->bind_result($title,$body);
    $stmt->fetch();
    $stmt->close();
    return array('title'=>$title,'body'=>$body);
  }else{
    trigger_error('Could Not Prepare Query',E_USER_WARNING);
    return false;
  } 
 
}
 
So here's the problem, query itself is correct as far as i know, i ran it in both phpmyadmin and cmd (running windows) and it returns what it's supposed to return. But here $body is always empty. It's as if bind_result() isn't passing retrieved data to the variable. No errors/warnings are generated. :banghead: Spent all night going through the variables, looking for typo's, var_dump'ing everything, even rewrote the whole thing from scratch. Desperately need help :/

Re: weird problem with mysqli

Posted: Thu Aug 06, 2009 3:49 am
by JAB Creations
Just some casual suggestions...

What did you set error reporting to? Here is the most sensitive level...

Code: Select all

error_reporting(E_ALL);
Are you echoing the MySQL query to the browser and then testing it or are you constructing it by compiling it manually?

Echo what any variables you have...and if you don't see what you would expect, echo the variable before it (going upwards in your code) until you see what you're expecting...and that will hopefully help you zero in on whatever is preventing your code from working.