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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.