Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8351445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:37:49+00:00 2026-06-09T08:37:49+00:00

I have a little (and stupid) problem: I’m building a PHP application using mysqli

  • 0

I have a little (and stupid) problem: I’m building a PHP application using mysqli and a MySQL server. When the application is loaded, a variable called $database is initialized using

$database = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);

This, of course, works perfectly. If I create an statement to do a query:

$stmt = $database->prepare('SELECT a, b, c FROM table WHERE a = ?');

This still works. But, if I try to create another statement without closing the previous one, sometimes works, and sometimes now. The error I get when the creation of the statement fails is:

Fatal error: Call to a member function bind_param() on a non-object

And my question is: why? What should I do, open a connection (new mysql(…)) every time I want to create a new statement (and I have another open)?

Example

$stmt = $database->prepare('SELECT a, b, c FROM table WHERE a = ?');
$stmt->bind_param('i', $aValue);
$stmt->execute();
/* do some other operations, without closing $stmt */
$stmt2 = $database->prepare('INSERT INTO table2 (e, f) VALUES (? ,?)');
// Now, $stmt2 isn't initialized, so when the next line is run, the app fails
$stmt2->bind_param('ss', $someValue, $anotherValue);

If, before the

$stmt2 = $database->prepare('INSERT INTO table2 (e, f) VALUES (? ,?)');

I add a simple

$stmt->close();

All works without any problems. So, what is the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:37:51+00:00Added an answer on June 9, 2026 at 8:37 am

    You cannot run another query until you have fetched all the results from the previous. Otherwise you will have to make a separate connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a stupid question, but I have a little problem with understanding
I have a little problem with PHP, probably for most of you it's a
I have a little problem with escaping table name. I was so stupid that
I have little unusual problem to solve. I need some hint or links to
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,
I have a little problem with encoding. The data in db is ok, when
I have a little sample application I was working on trying to get some
First a little introduction. We have an SQL Server Express 2008 database, which schema
Hi there, I have a little problem with a where query on a has_many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.