?
Solved

mysqli error...

Posted on 2013-05-28
9
Medium Priority
?
558 Views
Last Modified: 2013-05-28
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

0
Comment
Question by:aej1973
9 Comments
 
LVL 5

Expert Comment

by:sriramiyer
ID: 39203475
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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39203488
Do you have code to open the connection on that page before those lines?  http://us3.php.net/manual/en/mysqli.construct.php
0
 

Author Comment

by:aej1973
ID: 39203500
yes, the connection is open..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39203553
See the first user comment here http://php.net/manual/en/mysqli.query.php about "Couldn't fetch mysqli".
0
 

Author Comment

by:aej1973
ID: 39203558
ok, let me check.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39203562
You may also be missing a statement according to the example here: http://www.php.net/manual/en/mysqli.prepare.php
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 1200 total points
ID: 39203565
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
 

Author Comment

by:aej1973
ID: 39203588
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
 

Author Comment

by:aej1973
ID: 39203599
solved. Thanks Marcus.

if ($ph == false){
       die($mysqli->error);
           }
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question