Jump to content

Couldn't fetch mysqli_result


nblasgen

Recommended Posts

Seems to be the same issue here:

 

http://www.phpfreaks.com/forums/index.php?topic=222008.0

 

So I have what seems to be a very simple query.

 

$q = "SELECT asterisk_local_chan FROM AgentStatus";

$res = $db->query($q);

if ($db->errno) die (__FILE__ . '@' . __LINE__ . ': ' . $db->error);

while (list($channel) = $res->fetch_row())

{

...

}

$res->free();

 

So the query runs fine 99% of the time and trust me on that since I have the query running at least once ever 5 seconds.  But once in a while, the application crashes on:

 

PHP Warning:  mysqli_result::fetch_row(): Couldn't fetch mysqli_result in ... on line 34

PHP Warning:  mysqli_result::free(): Couldn't fetch mysqli_result in ... on line 64

 

So what could possibly cause $db to return a result set ($res) and not trigger an error.  Then when it comes time to read the data set ($res->fetch_row()) the data isn't there.  AgentStatus can get updated by multiple scripts.  I'm thinking maybe it's because of a race condition.  Can anyone speak to that?  Can anyone offer other ideas?

 

And just in case someone suggests it, I don't need to check the result set for !$res->num_rows because fetch_row() will return 0 on no data and the program wont have an issue.  An empty data set can still be free()'ed.

 

Link to comment
Share on other sites

The code in your while(){} loop is likely overwriting the result or your db class is not setting $db->errno under certain conditions. It would take seeing the code in your while(){} loop and the code of your db class to be able to help.

 

Edit: Another possibility would be if your db class contained an error that was destroying the result set under certain conditions, rather than explicit code in the while() loop.

 

Short answer - cannot really help you without full seeing all the relevant code responsible for the symptoms.

Link to comment
Share on other sites

The $res->fetch_row() is getting a warning itself.  That line comes 2 lines after the query and one line after the check for an error.

 

$q = "SELECT asterisk_local_chan FROM AgentStatus";

$res = $db->query($q);

if ($db->errno) die (__FILE__ . '@' . __LINE__ . ': ' . $db->error);

while (list($channel) = $res->fetch_row())

 

If we're running into errors that quickly I expect it to be another issue.  MySQL (by default) is a non-transaction based database.  My only guess would be that the data is no longer in the database between the time I make the query to the split second later that I fetch the data.

 

But yes, I would love to explore other ideas.  No, I don't think it has to do with overwriting $res or $db within those 3 lines.  Yes, it could be happening somewhere else in the application (I doubt it, but not impossible) but that shouldn't be important.

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.