/**
  * Transfers a result set from a prepared statement
  * @link http://www.php.net/manual/en/mysqli-stmt.store-result.php
  * @throws \mysqli_sql_exception
  * @return \classes\database\statement\MysqliPrepareStmt
  */
 public function storeResult()
 {
     if (!$this->stmt->store_result()) {
         throw new \mysqli_sql_exception('storeResult call fail');
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Execute
  *
  * @param  ParameterContainer $parameters
  * @return mixed
  */
 public function execute($parameters = null)
 {
     if (!$this->isPrepared) {
         $this->prepare();
     }
     /** START Standard ParameterContainer Merging Block */
     if (!$this->parameterContainer instanceof ParameterContainer) {
         if ($parameters instanceof ParameterContainer) {
             $this->parameterContainer = $parameters;
             $parameters = null;
         } else {
             $this->parameterContainer = new ParameterContainer();
         }
     }
     if (is_array($parameters)) {
         $this->parameterContainer->setFromArray($parameters);
     }
     if ($this->parameterContainer->count() > 0) {
         $this->bindParametersFromContainer();
     }
     /** END Standard ParameterContainer Merging Block */
     if ($this->resource->execute() === false) {
         throw new Exception\RuntimeException($this->resource->error);
     }
     if ($this->bufferResults === true) {
         $this->resource->store_result();
         $this->isPrepared = false;
         $buffered = true;
     } else {
         $buffered = false;
     }
     $result = $this->driver->createResult($this->resource, $buffered);
     return $result;
 }
Beispiel #3
0
 /**
  * Fetch for non-mysqlnd environments
  *
  * @todo review support for custom classes
  * @todo review pros/cons of using store_result()
  * @todo fix statements using AS
  *
  * @param $int_fetch_mode
  * @return array|null|object|\stdClass
  */
 private function fetchOldSchool($int_fetch_mode)
 {
     $this->obj_stmt->store_result();
     $obj_meta = $this->obj_stmt->result_metadata();
     $arr_fields = $obj_meta->fetch_fields();
     $obj_result = NULL !== $this->str_result_class ? new $this->str_result_class() : new \stdClass();
     $arr_bind_fields = array();
     foreach ($arr_fields as $obj_field) {
         $arr_bind_fields[] =& $obj_result->{$obj_field->name};
     }
     call_user_func_array(array($this->obj_stmt, 'bind_result'), $arr_bind_fields);
     if (DB::FETCH_MODE_ONE === $int_fetch_mode) {
         if ($this->obj_stmt->fetch()) {
             $mix_data = $obj_result;
         } else {
             $mix_data = NULL;
         }
     } else {
         $mix_data = array();
         while ($this->obj_stmt->fetch()) {
             // Manual clone method - nasty, but required because of all the binding references
             // to avoid each row being === the last row in the result set
             $obj_row = NULL !== $this->str_result_class ? new $this->str_result_class() : new \stdClass();
             foreach ($arr_fields as $obj_field) {
                 $obj_row->{$obj_field->name} = $obj_result->{$obj_field->name};
             }
             $mix_data[] = $obj_row;
         }
     }
     $this->obj_stmt->free_result();
     return $mix_data;
 }
 /**
  * Binds this statement to the variables
  */
 protected function bind()
 {
     $variables = array();
     // Bind each field
     while ($field = $this->metadata->fetch_field()) {
         $this->columns[] = $field->name;
         // Note that while boundValues isn't initialised at this point,
         // later calls to $this->statement->fetch() Will populate
         // $this->boundValues later with the next result.
         $variables[] =& $this->boundValues[$field->name];
     }
     call_user_func_array(array($this->statement, 'bind_result'), $variables);
     $this->bound = true;
     $this->metadata->free();
     // Buffer all results
     $this->statement->store_result();
 }
Beispiel #5
0
 public function store_result()
 {
     $retval = $this->statement->store_result();
     if (false === $retval) {
         throw new BeeHub_MySQL(self::mysqli()->error, self::mysqli()->errno);
     }
     return $retval;
 }
Beispiel #6
0
 /**
  * Executes a prepared statement.
  *
  * @param array $params OPTIONAL Values to bind to parameter placeholders.
  * @return bool
  * @throws Zend_Db_Statement_Mysqli_Exception
  */
 public function _execute(array $params = null)
 {
     if (!$this->_stmt) {
         return false;
     }
     // if no params were given as an argument to execute(),
     // then default to the _bindParam array
     if ($params === null) {
         $params = $this->_bindParam;
     }
     // send $params as input parameters to the statement
     if ($params) {
         array_unshift($params, str_repeat('s', count($params)));
         call_user_func_array(array($this->_stmt, 'bind_param'), $params);
     }
     // execute the statement
     $retval = $this->_stmt->execute();
     if ($retval === false) {
         /**
          * @see Zend_Db_Statement_Mysqli_Exception
          */
         require_once 'Zend/Db/Statement/Mysqli/Exception.php';
         throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement execute error : " . $this->_stmt->error);
     }
     // retain metadata
     if ($this->_meta === null) {
         $this->_meta = $this->_stmt->result_metadata();
         if ($this->_stmt->errno) {
             /**
              * @see Zend_Db_Statement_Mysqli_Exception
              */
             require_once 'Zend/Db/Statement/Mysqli/Exception.php';
             throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement metadata error: " . $this->_stmt->error);
         }
     }
     // statements that have no result set do not return metadata
     if ($this->_meta !== false) {
         // get the column names that will result
         $this->_keys = array();
         foreach ($this->_meta->fetch_fields() as $col) {
             $this->_keys[] = $this->_adapter->foldCase($col->name);
         }
         // set up a binding space for result variables
         $this->_values = array_fill(0, count($this->_keys), null);
         // set up references to the result binding space.
         // just passing $this->_values in the call_user_func_array()
         // below won't work, you need references.
         $refs = array();
         foreach ($this->_values as $i => &$f) {
             $refs[$i] =& $f;
         }
         $this->_stmt->store_result();
         // bind to the result variables
         call_user_func_array(array($this->_stmt, 'bind_result'), $this->_values);
     }
     return $retval;
 }
 /**
  * Force buffering
  *
  * @throws Exception\RuntimeException
  */
 public function buffer()
 {
     if ($this->resource instanceof \mysqli_stmt && $this->isBuffered !== true) {
         if ($this->position > 0) {
             throw new Exception\RuntimeException('Cannot buffer a result set that has started iteration.');
         }
         $this->resource->store_result();
         $this->isBuffered = true;
     }
 }
 /**
  * Get all array data
  *
  * @return array
  */
 public function getFetchArrays()
 {
     $data = array();
     if ($this->resource instanceof \mysqli_result) {
         $result = $this->resource;
     } else {
         if ($this->resource instanceof \mysqli_stmt) {
             $result = $this->resource->get_result();
         } else {
             if ($this->resource instanceof \mysqli) {
                 $result = $this->resource->store_result();
             }
         }
     }
     while ($row = $result->fetch_array(\MYSQLI_ASSOC)) {
         $data[] = $row;
     }
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function execute($params = null)
 {
     if (null !== $this->_bindedValues) {
         if (null !== $params) {
             if (!$this->_bindValues($params)) {
                 throw new MysqliException($this->_stmt->error, $this->_stmt->errno);
             }
         } else {
             if (!call_user_func_array(array($this->_stmt, 'bind_param'), $this->_bindedValues)) {
                 throw new MysqliException($this->_stmt->error, $this->_stmt->errno);
             }
         }
     }
     if (!$this->_stmt->execute()) {
         throw new MysqliException($this->_stmt->error, $this->_stmt->errno);
     }
     if (null === $this->_columnNames) {
         $meta = $this->_stmt->result_metadata();
         if (false !== $meta) {
             $columnNames = array();
             foreach ($meta->fetch_fields() as $col) {
                 $columnNames[] = $col->name;
             }
             $meta->free();
             $this->_columnNames = $columnNames;
             $this->_rowBindedValues = array_fill(0, count($columnNames), NULL);
             $refs = array();
             foreach ($this->_rowBindedValues as $key => &$value) {
                 $refs[$key] =& $value;
             }
             if (!call_user_func_array(array($this->_stmt, 'bind_result'), $refs)) {
                 throw new MysqliException($this->_stmt->error, $this->_stmt->errno);
             }
         } else {
             $this->_columnNames = false;
         }
     }
     // We have a result.
     if (false !== $this->_columnNames) {
         $this->_stmt->store_result();
     }
     return true;
 }
Beispiel #10
0
 /**
  * Gets the results of the query
  */
 private function _getResults()
 {
     $meta = $this->_query->result_metadata();
     $parameters = array();
     $results = array();
     $row = array();
     while ($field = $meta->fetch_field()) {
         $row[$field->name] = null;
         $parameters[] =& $row[$field->name];
     }
     if (version_compare(phpversion(), '5.4', '<')) {
         $this->_query->store_result();
     }
     call_user_func_array(array($this->_query, 'bind_result'), $parameters);
     while ($this->_query->fetch()) {
         $x = array();
         foreach ($row as $key => $val) {
             $x[$key] = $val;
         }
         array_push($results, $x);
     }
     $this->_last_result = $results;
 }
Beispiel #11
0
 /**
  * Execute
  *
  * @param  null|array|Parameters $parameters
  * @throws Exception\RuntimeException
  * @return Result
  */
 public function execute($parameters = null)
 {
     if (!$this->isPrepared) {
         $this->prepare();
     }
     if (!$this->parameters instanceof Parameters) {
         if ($parameters instanceof Parameters) {
             $this->parameters = $parameters;
             $parameters = null;
         } else {
             $this->parameters = new Parameters();
         }
     }
     if (is_array($parameters)) {
         $this->parameters->setFromArray($parameters);
     }
     if ($this->parameters->count() > 0) {
         $this->bindParameters();
     }
     $return = $this->resource->execute();
     if ($return === false) {
         if (in_array($this->resource->errno, array(1060, 1061, 1062))) {
             throw new Exception\DuplicateException($this->resource->error, $this->resource->errno);
         }
         throw new Exception\RuntimeException($this->resource->error);
     }
     if ($this->bufferResults === true) {
         $this->resource->store_result();
         $this->isPrepared = false;
         $buffered = true;
     } else {
         $buffered = false;
     }
     $result = $this->driver->createResult($this->resource, $buffered);
     return $result;
 }
Beispiel #12
0
 /**
  * Executes the specified MySQLi statement, stores the result and resets the
  * cache for things like where clauses, etc
  *
  * @param mysqli_stmt $statement The MySQLi statement that was prepared and is
  *  now ready to be executed
  */
 protected static function _execute($statement)
 {
     $statement->execute();
     $statement->store_result();
     self::_reset_cache();
 }
Beispiel #13
0
 function fetchAll()
 {
     if (!$this->DB) {
         return;
     }
     $data = $this->Statement->result_metadata();
     $out = array();
     $fields = array();
     if (!$data) {
         return null;
     }
     $length = 0;
     while (null != ($field = mysqli_fetch_field($data))) {
         $fields[] =& $out[$field->name];
         $length += $field->length;
     }
     call_user_func_array(array($this->Statement, "bind_result"), $fields);
     $output = array();
     $count = 0;
     //FIXME: store_result is needed, but using it causes crash
     if ($length >= 1000000) {
         if (!$this->Statement->store_result()) {
             throw new \Exception("Store_Result error on MySQLi prepared statement : " . $this->Statement->get_warnings());
         }
     }
     while ($this->Statement->fetch()) {
         foreach ($out as $k => $v) {
             $output[$count][$k] = $v;
         }
         $count++;
     }
     $this->Statement->free_result();
     return $count == 0 ? null : $output;
 }
 /**
  * This helper method takes care of prepared statements' "bind_result method
  * , when the number of variables to pass is unknown.
  *
  * @param mysqli_stmt $stmt Equal to the prepared statement object.
  *
  * @return array The results of the SQL fetch.
  */
 protected function _dynamicBindResults(mysqli_stmt $stmt)
 {
     $parameters = array();
     $results = array();
     // See http://php.net/manual/en/mysqli-result.fetch-fields.php
     $mysqlLongType = 252;
     $shouldStoreResult = false;
     $meta = $stmt->result_metadata();
     // if $meta is false yet sqlstate is true, there's no sql error but the query is
     // most likely an update/insert/delete which doesn't produce any results
     if (!$meta && $stmt->sqlstate) {
         return array();
     }
     $row = array();
     while ($field = $meta->fetch_field()) {
         if ($field->type == $mysqlLongType) {
             $shouldStoreResult = true;
         }
         if ($this->_nestJoin && $field->table != $this->_tableName) {
             $field->table = substr($field->table, strlen(self::$prefix));
             $row[$field->table][$field->name] = null;
             $parameters[] =& $row[$field->table][$field->name];
         } else {
             $row[$field->name] = null;
             $parameters[] =& $row[$field->name];
         }
     }
     // avoid out of memory bug in php 5.2 and 5.3. Mysqli allocates lot of memory for long*
     // and blob* types. So to avoid out of memory issues store_result is used
     // https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119
     if ($shouldStoreResult) {
         $stmt->store_result();
     }
     call_user_func_array(array($stmt, 'bind_result'), $parameters);
     $this->totalCount = 0;
     $this->count = 0;
     while ($stmt->fetch()) {
         if ($this->returnType == 'Object') {
             $x = new stdClass();
             foreach ($row as $key => $val) {
                 if (is_array($val)) {
                     $x->{$key} = new stdClass();
                     foreach ($val as $k => $v) {
                         $x->{$key}->{$k} = $v;
                     }
                 } else {
                     $x->{$key} = $val;
                 }
             }
         } else {
             $x = array();
             foreach ($row as $key => $val) {
                 $x[$key] = $val;
             }
         }
         $this->count++;
         array_push($results, $x);
     }
     if ($shouldStoreResult) {
         $stmt->free_result();
     }
     $stmt->close();
     // stored procedures sometimes can return more then 1 resultset
     if ($this->mysqli()->more_results()) {
         $this->mysqli()->next_result();
     }
     if (in_array('SQL_CALC_FOUND_ROWS', $this->_queryOptions)) {
         $stmt = $this->mysqli()->query('SELECT FOUND_ROWS()');
         $totalCount = $stmt->fetch_row();
         $this->totalCount = $totalCount[0];
     }
     if ($this->returnType == 'Json') {
         return json_encode($results);
     }
     return $results;
 }
Beispiel #15
0
 protected function _dynamicBindResults(mysqli_stmt $stmt)
 {
     $parameters = array();
     $results = array();
     $meta = $stmt->result_metadata();
     if (!$meta && $stmt->sqlstate) {
         return array();
     }
     $row = array();
     while ($field = $meta->fetch_field()) {
         $row[$field->name] = null;
         $parameters[] =& $row[$field->name];
     }
     if (version_compare(phpversion(), '5.4', '<')) {
         $stmt->store_result();
     }
     call_user_func_array(array($stmt, 'bind_result'), $parameters);
     $this->totalCount = 0;
     $this->count = 0;
     while ($stmt->fetch()) {
         $x = array();
         foreach ($row as $key => $val) {
             $x[$key] = $val;
         }
         $this->count++;
         array_push($results, $x);
     }
     if ($this->_mysqli->more_results()) {
         $this->_mysqli->next_result();
     }
     if ($this->fetchTotalCount === true) {
         $this->fetchTotalCount = false;
         $stmt = $this->_mysqli->query('SELECT FOUND_ROWS();');
         $totalCount = $stmt->fetch_row();
         $this->totalCount = $totalCount[0];
     }
     return $results;
 }
Beispiel #16
0
?>


<?php 
require_once "../resources/templates/menu.php";
?>

<?php 
$id = $_GET['id'];
$stmt = new mysqli_stmt($mysqli, "SELECT first_name, last_name, description, country, dob, file_ext FROM users WHERE id = ?");
$stmt1 = new mysqli_stmt($mysqli, "SELECT COUNT(user_id)FROM adventures WHERE user_id = ?");
if ($stmt1) {
    $stmt1->bind_param("i", $id);
    $stmt1->execute();
    $stmt1->bind_result($adventure_no);
    $stmt1->store_result();
    if ($stmt1->num_rows() == 1) {
        while ($stmt1->fetch()) {
            if ($stmt) {
                $stmt->bind_param("i", $id);
                if ($stmt->execute()) {
                    $stmt->bind_result($first_name, $last_name, $description, $country, $dob, $ext);
                    $stmt->store_result();
                    if ($stmt->num_rows() == 1) {
                        while ($stmt->fetch()) {
                            ?>
<body>
<div class="container">
    <div class="row">

        <div id="Author" class="container">
Beispiel #17
0
            }
        }
    }
}
?>

    <?php 
$commentArray[] = array();
$sql = "SELECT * FROM comments WHERE adv_id = {$adv_id}";
$res = $mysqli->query($sql) or trigger_error($mysqli->error . "[{$sql}]");
while ($row = $res->fetch_assoc()) {
    $stmt3 = new mysqli_stmt($mysqli, "SELECT first_name, last_name FROM users WHERE id = ?");
    $stmt3->bind_param("i", $row['user_id']);
    $stmt3->execute();
    $stmt3->bind_result($commentFirstName, $commentLastName);
    $stmt3->store_result();
    if ($stmt3->num_rows() == 1) {
        while ($stmt3->fetch()) {
            ?>


                <div class="row">
                    <div
                        class="col-md-6 col-md-offset-1 comments-section">


                        <section>
                            <div class="">
                                <label
                                    class=""><?php 
            echo $commentFirstName;
 /**
  * This helper method takes care of prepared statements' "bind_result method
  * , when the number of variables to pass is unknown.
  *
  * @param mysqli_stmt $stmt Equal to the prepared statement object.
  *
  * @return array The results of the SQL fetch.
  */
 protected function _dynamicBindResults(mysqli_stmt $stmt)
 {
     $parameters = array();
     $results = array();
     $meta = $stmt->result_metadata();
     // if $meta is false yet sqlstate is true, there's no sql error but the query is
     // most likely an update/insert/delete which doesn't produce any results
     if (!$meta && $stmt->sqlstate) {
         return array();
     }
     $row = array();
     while ($field = $meta->fetch_field()) {
         $row[$field->name] = null;
         $parameters[] =& $row[$field->name];
     }
     // avoid out of memory bug in php 5.2 and 5.3
     // https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119
     if (version_compare(phpversion(), '5.4', '<')) {
         $stmt->store_result();
     }
     call_user_func_array(array($stmt, 'bind_result'), $parameters);
     while ($stmt->fetch()) {
         $x = array();
         foreach ($row as $key => $val) {
             $x[$key] = $val;
         }
         $this->count++;
         array_push($results, $x);
     }
     return $results;
 }
Beispiel #19
0
 private function _dynamicBindResults(mysqli_stmt $stmt)
 {
     $parameters = array();
     $results = array();
     $meta = $stmt->result_metadata();
     if (!$meta && $stmt->sqlstate) {
         return array();
     }
     $row = array();
     while ($field = $meta->fetch_field()) {
         $row[$field->name] = null;
         $parameters[] =& $row[$field->name];
     }
     $stmt->store_result();
     call_user_func_array(array($stmt, 'bind_result'), $parameters);
     $this->count = 0;
     while ($stmt->fetch()) {
         $result = array();
         foreach ($row as $key => $val) {
             $result[$key] = $val;
         }
         array_push($results, (object) $result);
         $this->count++;
     }
     $stmt->free_result();
     return $results;
 }
Beispiel #20
0
 /**
  * This helper method takes care of prepared statements' "bind_result method
  * , when the number of variables to pass is unknown.
  *
  * @param mysqli_stmt $stmt Equal to the prepared statement object.
  *
  * @return array The results of the SQL fetch.
  */
 protected function _dynamicBindResults(mysqli_stmt $stmt)
 {
     $parameters = array();
     $results = array();
     $meta = $stmt->result_metadata();
     // if $meta is false yet sqlstate is true, there's no sql error but the query is
     // most likely an update/insert/delete which doesn't produce any results
     if (!$meta && $stmt->sqlstate) {
         return array();
     }
     $row = array();
     while ($field = $meta->fetch_field()) {
         $row[$field->name] = null;
         $parameters[] =& $row[$field->name];
     }
     // avoid out of memory bug in php 5.2 and 5.3
     //if (version_compare (phpversion(), '5.4', '<'))
     // NOTE: Always store results, because it seems that memory bug in php 5.2 and 5.3 has re-surfaced
     $stmt->store_result();
     call_user_func_array(array($stmt, 'bind_result'), $parameters);
     $this->count = 0;
     while ($stmt->fetch()) {
         $x = array();
         foreach ($row as $key => $val) {
             $x[$key] = $val;
         }
         $this->count++;
         array_push($results, $x);
     }
     return $results;
 }
 /**
  * Executes the prepared statement. If the prepared statement included parameter
  * markers, you must either:
  * <ul>
  * <li>call {@link \TYPO3\CMS\Core\Database\PreparedStatement::bindParam()} to bind PHP variables
  * to the parameter markers: bound variables pass their value as input</li>
  * <li>or pass an array of input-only parameter values</li>
  * </ul>
  *
  * $input_parameters behave as in {@link \TYPO3\CMS\Core\Database\PreparedStatement::bindParams()}
  * and work for both named parameters and question mark parameters.
  *
  * Example 1:
  * <code>
  * $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'bugs', 'reported_by = ? AND bug_status = ?');
  * $statement->execute(array('goofy', 'FIXED'));
  * </code>
  *
  * Example 2:
  * <code>
  * $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'bugs', 'reported_by = :nickname AND bug_status = :status');
  * $statement->execute(array(':nickname' => 'goofy', ':status' => 'FIXED'));
  * </code>
  *
  * @param array $input_parameters An array of values with as many elements as there are bound parameters in the SQL statement being executed. The PHP type of each array value will be used to decide which PARAM_* type to use (int, string, boolean, NULL), so make sure your variables are properly casted, if needed.
  * @return bool Returns TRUE on success or FALSE on failure.
  * @throws \InvalidArgumentException
  * @api
  */
 public function execute(array $input_parameters = array())
 {
     $parameterValues = $this->parameters;
     if (!empty($input_parameters)) {
         $parameterValues = array();
         foreach ($input_parameters as $key => $value) {
             $parameterValues[$key] = array('value' => $value, 'type' => $this->guessValueType($value));
         }
     }
     if ($this->statement !== NULL) {
         // The statement has already been executed, we try to reset it
         // for current run but will set it to NULL if it fails for some
         // reason, just as if it were the first run
         if (!@$this->statement->reset()) {
             $this->statement = NULL;
         }
     }
     if ($this->statement === NULL) {
         // The statement has never been executed so we prepare it and
         // store it for further reuse
         $query = $this->query;
         $precompiledQueryParts = $this->precompiledQueryParts;
         $this->convertNamedPlaceholdersToQuestionMarks($query, $parameterValues, $precompiledQueryParts);
         if (!empty($precompiledQueryParts)) {
             $query = implode('', $precompiledQueryParts['queryParts']);
         }
         $this->statement = $GLOBALS['TYPO3_DB']->prepare_PREPAREDquery($query, $precompiledQueryParts);
         if ($this->statement === NULL) {
             return FALSE;
         }
     }
     $combinedTypes = '';
     $values = array();
     foreach ($parameterValues as $parameterValue) {
         switch ($parameterValue['type']) {
             case self::PARAM_NULL:
                 $type = 's';
                 $value = NULL;
                 break;
             case self::PARAM_INT:
                 $type = 'i';
                 $value = (int) $parameterValue['value'];
                 break;
             case self::PARAM_STR:
                 $type = 's';
                 $value = $parameterValue['value'];
                 break;
             case self::PARAM_BOOL:
                 $type = 'i';
                 $value = $parameterValue['value'] ? 1 : 0;
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Unknown type %s used for parameter %s.', $parameterValue['type'], $key), 1281859196);
         }
         $combinedTypes .= $type;
         $values[] = $value;
     }
     // ->bind_param requires second up to last arguments as references
     if (!empty($combinedTypes)) {
         $bindParamArguments = array();
         $bindParamArguments[] = $combinedTypes;
         $numberOfExtraParamArguments = count($values);
         for ($i = 0; $i < $numberOfExtraParamArguments; $i++) {
             $bindParamArguments[] =& $values[$i];
         }
         call_user_func_array(array($this->statement, 'bind_param'), $bindParamArguments);
     }
     $success = $this->statement->execute();
     // Store result
     if (!$success || $this->statement->store_result() === FALSE) {
         return FALSE;
     }
     if (empty($this->fields)) {
         // Store the list of fields
         if ($this->statement instanceof \mysqli_stmt) {
             $result = $this->statement->result_metadata();
             if ($result instanceof \mysqli_result) {
                 $fields = $result->fetch_fields();
                 $result->close();
             }
         } else {
             $fields = $this->statement->fetch_fields();
         }
         if (is_array($fields)) {
             foreach ($fields as $field) {
                 $this->fields[] = $field->name;
             }
         }
     }
     // New result set available
     $this->buffer = NULL;
     // Empty binding parameters
     $this->parameters = array();
     // Return the success flag
     return $success;
 }
 /**
  * This helper method takes care of prepared statements' "bind_result method
  * , when the number of variables to pass is unknown.
  *
  * @param mysqli_stmt $stmt Equal to the prepared statement object.
  *
  * @return array The results of the SQL fetch.
  */
 protected function _dynamicBindResults(mysqli_stmt $stmt)
 {
     $parameters = array();
     $results = array();
     $meta = $stmt->result_metadata();
     // if $meta is false yet sqlstate is true, there's no sql error but the query is
     // most likely an update/insert/delete which doesn't produce any results
     if (!$meta && $stmt->sqlstate) {
         return array();
     }
     $row = array();
     while ($field = $meta->fetch_field()) {
         $row[$field->name] = null;
         $parameters[] =& $row[$field->name];
     }
     $stmt->store_result();
     call_user_func_array(array($stmt, 'bind_result'), $parameters);
     while ($stmt->fetch()) {
         $x = array();
         foreach ($row as $key => $val) {
             $x[$key] = $val;
         }
         $this->count++;
         array_push($results, $x);
     }
     return $results;
 }
Beispiel #23
0
 /**
  * This helper method takes care of prepared statements' "bind_result method
  * , when the number of variables to pass is unknown.
  *
  * @param mysqli_stmt $stmt Equal to the prepared statement object.
  *
  * @return array The results of the SQL fetch.
  */
 protected function _dynamicBindResults(mysqli_stmt $stmt)
 {
     $parameters = array();
     $results = array();
     $meta = $stmt->result_metadata();
     // if $meta is false yet sqlstate is true, there's no sql error but the query is
     // most likely an update/insert/delete which doesn't produce any results
     if (!$meta && $stmt->sqlstate) {
         return array();
     }
     $row = array();
     while ($field = $meta->fetch_field()) {
         $row[$field->name] = null;
         $parameters[] =& $row[$field->name];
     }
     // avoid out of memory bug in php 5.2 and 5.3
     // https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119
     if (version_compare(phpversion(), '5.4', '<')) {
         $stmt->store_result();
     }
     call_user_func_array(array($stmt, 'bind_result'), $parameters);
     $this->totalCount = 0;
     $this->count = 0;
     while ($stmt->fetch()) {
         $x = array();
         foreach ($row as $key => $val) {
             $x[$key] = $val;
         }
         ++$this->count;
         array_push($results, $x);
     }
     // stored procedures sometimes can return more then 1 resultset
     if ($this->_mysqli->more_results()) {
         $this->_mysqli->next_result();
     }
     if (in_array('SQL_CALC_FOUND_ROWS', $this->_queryOptions)) {
         $stmt = $this->_mysqli->query('SELECT FOUND_ROWS()');
         $totalCount = $stmt->fetch_row();
         $this->totalCount = $totalCount[0];
     }
     return $results;
 }