2

Having an issue with prepared statement where no results are returned. Upon examining MySql's general query log, I can see where the connection is being made, but there never appears to be a query executed.

After adding mysqli_report(MYSQLI_REPORT_ALL), the following error message is returned:

Unknown prepared statement handler (4) given to mysqld_stmt_execute

The following is the code executing the prepared statement:

$something_in = 'a-string-of-text';

if($stmt = $this->prepare("SELECT first, last, phone FROM people WHERE something=? ORDER BY last ASC")){

   try{

       if (!$stmt->bind_param('s', $something_in)) {
          die('bind_param() failed: ' . htmlspecialchars($stmt->error));
        } 

       $stmt->execute();
       $stmt->bind_result($first, $last, $something, $phone);

       while($stmt->fetch()){

           $returnArray[] = array(
               'first_name'    => $first,
               'last_name'     => $last,
               'something'     => $something,
               'phone'         => $phone
           );

       }

       $stmt->free_result();
       $stmt->close();

       return $returnArray; // we make it to here with a blank array instead of expected results

   } catch (Exception $ex) {

       return $ex->getMessage();

   }

}

Has anyone else run into this issue? It seems rather odd.

MySQL Version: 5.6

PHP Version: 7

Also another useful piece of information would be that we're using netscaler which acts as a proxy between our app servers and database servers. I'm inclined to believe this might be where the hangup is happening.

EDIT

Confirmed this is in relation to our netscaler proxy as connecting app server directly to db server resolves the issue. Will post solution once cause determined.

whitwhoa
  • 2,389
  • 4
  • 30
  • 61
  • Try checking for [mysqli errors](http://php.net/manual/en/mysqli.error.php) along the way. – aynber Mar 16 '18 at 16:01
  • Might want `store_result()` in there [as I had pointed out to me the other day](https://stackoverflow.com/questions/49197768/session-destroyed-after-page-reload) – CD001 Mar 16 '18 at 16:06
  • A lot of problems can be detected and resolved by [enabling exceptions in `mysqli`](https://stackoverflow.com/questions/14578243/turning-query-errors-to-exceptions-in-mysqli) so mistakes aren't easily ignored. – tadman Mar 16 '18 at 16:45
  • Updated question with results obtained after enabling exceptions in mysqli. – whitwhoa Mar 16 '18 at 18:06

1 Answers1

0

A solution for this particular edge case has not yet been identified. However moving away from mysqli and using php's PDO library has resolved the dilemma for the short term.

whitwhoa
  • 2,389
  • 4
  • 30
  • 61