mysqli error...

Hi, I am running this query and I keep get the following error, can someone let me know what is wrong here?


Warning: mysqli::prepare(): Couldn't fetch mysqli in /var/www/voicebox/home_user.php on line 87

Fatal error: Call to a member function bind_param() on a non-object in /var/www/voicebox/home_user.php on line 88


$ph=$mysqli->prepare("select did_number from did_numbers where assigned_to=? and did_status='1'");
   $ph->bind_param("i",$userid);
   $ph->execute();
   $ph->fetch();
   $ph ->store_result();   
   $phCount=$ph->num_rows;
   if($phCount==0)
   $rowCount="No  Lines";
       else {
		       $rowCount=$phCount;
                 }   

Open in new window

aej1973Asked:
Who is Participating?
 
Marco GasiFreelancerCommented:
Try this:

$ph=$mysqli->prepare("select did_number from did_numbers where assigned_to=? and did_status='1'");
if ($ph === false){
  die(mysqli->error();
}
$ph->bind_param("i",$userid);

Since mysqli->prepare return false if it fails, this way you'll can get the specific mysqli error-
0
 
sriramiyerCommented:
insert this sqlstr code for debugging purpose to get valid sqlstr or not first,

$sqlstr="select did_number from did_numbers where assigned_to=? and did_status='1'";
echo $sqlstr . "</br>";
exit;
mysqli->prepare("select did_number from did_numbers where assigned_to=? and did_status='1'");
0
 
Dave BaldwinFixer of ProblemsCommented:
Do you have code to open the connection on that page before those lines?  http://us3.php.net/manual/en/mysqli.construct.php
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
aej1973Author Commented:
yes, the connection is open..
0
 
Dave BaldwinFixer of ProblemsCommented:
See the first user comment here http://php.net/manual/en/mysqli.query.php about "Couldn't fetch mysqli".
0
 
aej1973Author Commented:
ok, let me check.
0
 
Dave BaldwinFixer of ProblemsCommented:
You may also be missing a statement according to the example here: http://www.php.net/manual/en/mysqli.prepare.php
0
 
aej1973Author Commented:
Marcus, this is the error I am getting...

Fatal error: Call to undefined method mysqli::error() in /var/www/voicebox/home_user.php on line 92
0
 
aej1973Author Commented:
solved. Thanks Marcus.

if ($ph == false){
       die($mysqli->error);
           }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.