Beispiel #1
0
 /**
  * Fetches the result from a prepared query.
  *
  * @param \MYSQLi_STMT $query The prepared query to fetch the result from.
  *
  * @return string[] The result array or null in case we have no result.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 09.03.2010<br />
  */
 private function fetchBindResult(\mysqli_stmt $query)
 {
     $result = null;
     do {
         $metaData = $query->result_metadata();
         // in case the meta data is not present (e.g. for INSERT statements),
         // we cannot fetch any data. thus we return null to indicate no result
         if ($metaData === false) {
             break;
         }
         $resultRow = [];
         $resultParams = [];
         while ($field = $metaData->fetch_field()) {
             $resultParams[] =& $resultRow[$field->name];
         }
         $bindResult = [];
         call_user_func_array([&$query, 'bind_result'], $resultParams);
         while ($query->fetch()) {
             $currentRow = [];
             foreach ($resultRow as $key => $val) {
                 $currentRow[$key] = $val;
             }
             $bindResult[] = $currentRow;
         }
         $result[] = $bindResult;
     } while ($query->more_results() && $query->next_result());
     // for sprocs
     return count($result) === 1 ? $result[0] : $result;
 }