Jump to content

Error with mysqli handling NO resultset, not NULL resultset


jugdish114

Recommended Posts

I am having an issue where the output from a MySQL stored procedure is not handled correctly, when there is NO resultset, as opposed to a NULL resultset.  For example:

 

1) select * from myTable; //this works, there are 0,1, multiple records returned

 

2) select * from myTable where 1=2;  //this works, there are 0 records returned in a NULL resultset

 

3)  set user_level = 'user';

     if user_level = 'admin' then

         select * from myTable;    //this never hits

     end if;    

 

There is an error in #3, the query is never touched, so NO resultset is returned.  This is different from what happens in example #2, where a resultset is returned, it is just NULL.

 

My code looks like this:

 

      if ( ($result = $mysqli_conn->query($SQL)) == false )
      {
        printf("Invalid query: %s\nWhole query: %s\n", $mysqli_conn->error, $SQL);
      }
      else {
        while ($myrow = $result->fetch_array(MYSQLI_ASSOC)) 
        {
              ... do something here
        }
 
Any thoughts on how to handle this cleanly?  Thanks all,
 
Frank
Link to comment
Share on other sites

  • 2 weeks later...
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.