Jump to content

[SOLVED] MySQLi Error - Couldn't fetch mysqli


Syphon

Recommended Posts

I'm experiencing a very odd error. I'm converting our Data Access object to use the mysqli api. The conversion went through fine and the object uses the new api as expected.

 

There is one page, with one query in particular that seems to "unset" the mysqli object. A null result set is returned. When I try to access the $MySQLi->errno property, I get this error

 

Unknown Error: Couldn't fetch mysqli

 

Suddenly my object becomes broken!

I'm not calling ANY close methods on the result objects or mysqli objects.

Many of the other pages work fine, and executing the query in phpmyadmin yields valid results.

 

Google turned up only a handful of links related to this issue. Is there obscure issues with the mysqli api that aren't documented?

As I mentioned before, I'm not closing any of the returned result objects. Could it be a reached a limit and broke mysqli?

Link to comment
Share on other sites

As I mentioned before, I'm not closing any of the returned result objects. Could it be a reached a limit and broke mysqli?

That doesn't sound consitent with the fact that it's the same page.  Comment out all of your code, uncomment block by block, you'll find it.

Link to comment
Share on other sites

Found the issue. It's a little complicated to explain, but I'll give it a shot.

Each table of the database has it's respective class in php. Each class has a load function, which will take the parameter give and load itself

 

The DAL object which every single class uses, is referenced to one object. In other words, every single class uses the exact same object to talk to the database. One connection and tons of queries

 

When a class is serialized (the only one that is serialized currently is the user object), the DAL class is serialized along with it.

 

Now the user navigates to another page. A new DAL is constructed right off the bat. The session is checked and if someone exists, the page user object is instantiated and the session is unserialized.

 

That's the problem. The unserialized DAL in the newly created user object and the DAL object constructed on the page first load are not the same objects. It unserializes successfully, but I'm guessing that something inside the mysqli object needed to be refreshed.

 

Simply adding a __wakeup() and pointing the user object DAL back to the newly constructed one fixed this issue.

 

Hope that made sense.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.