当前位置: 首页>>代码示例>>PHP>>正文


PHP mysqli_stmt::result_metadata方法代码示例

本文整理汇总了PHP中mysqli_stmt::result_metadata方法的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_stmt::result_metadata方法的具体用法?PHP mysqli_stmt::result_metadata怎么用?PHP mysqli_stmt::result_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mysqli_stmt的用法示例。


在下文中一共展示了mysqli_stmt::result_metadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fetchOldSchool

 /**
  * 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;
 }
开发者ID:p13eater,项目名称:php-dbal,代码行数:42,代码来源:Statement.php

示例2: getOneRow

 /**
  * Get one row of data
  *
  * @return array|null
  * @access protected
  */
 protected function getOneRow()
 {
     if (null === $this->cols) {
         $result = $this->statement->result_metadata();
         if (false === $result) {
             return false;
         }
         $this->cols = [];
         // set column name
         foreach ($result->fetch_fields() as $col) {
             $this->cols[] = $col->name;
         }
         // bind values
         $this->vals = array_fill(0, count($this->cols), null);
         $refs = [];
         foreach ($this->vals as $i => &$f) {
             $refs[$i] =& $f;
         }
         call_user_func_array([$this->statement, 'bind_result'], $refs);
     }
     if ($this->statement->fetch()) {
         $row = [];
         foreach ($this->cols as $i => $col) {
             $row[$col] = $this->vals[$i];
         }
         return $row;
     }
     return false;
 }
开发者ID:phossa,项目名称:phossa-db,代码行数:35,代码来源:Result.php

示例3: fetchResource

 /**
  * @param \mysqli_stmt $resource
  * @param string       $column
  *
  * @return mixed[]
  */
 protected function fetchResource($resource, $column)
 {
     $result = [];
     $metadata = $resource->result_metadata();
     $fields = $metadata->fetch_fields();
     if (count($fields) == 0) {
         return [];
     }
     $variables = [];
     $data = [];
     foreach ($fields as $field) {
         $variables[] =& $data[$field->name];
     }
     $resource->bind_result(...$variables);
     while ($resource->fetch()) {
         $clone = [];
         foreach ($data as $key => $value) {
             $clone[$key] = $value;
         }
         $result[] = $clone;
     }
     $resource->free_result();
     $this->fixTypes($result, $fields, $column);
     return $result;
 }
开发者ID:binsoul,项目名称:db-platform-mysql,代码行数:31,代码来源:StatementResult.php

示例4: loadDataFromMysqliStatement

 /**
  * Mysqli's binding and returning of statement values
  * Mysqli requires you to bind variables to the extension in order to
  * get data out.  These values have to be references:
  *
  * @see http://php.net/manual/en/mysqli-stmt.bind-result.php
  * @throws Exception\RuntimeException
  * @return bool
  */
 protected function loadDataFromMysqliStatement()
 {
     $data = null;
     // build the default reference based bind structure, if it does not already exist
     if ($this->statementBindValues['keys'] === null) {
         $this->statementBindValues['keys'] = array();
         /* @var $resultResource \mysqli_result */
         $resultResource = $this->resource->result_metadata();
         foreach ($resultResource->fetch_fields() as $col) {
             $this->statementBindValues['keys'][] = $col->name;
         }
         $this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null);
         $refs = array();
         foreach ($this->statementBindValues['values'] as $i => &$f) {
             $refs[$i] =& $f;
         }
         call_user_func_array(array($this->resource, 'bind_result'), $this->statementBindValues['values']);
     }
     if (($r = $this->resource->fetch()) === null) {
         if (!$this->isBuffered) {
             $this->resource->close();
         }
         return false;
     } elseif ($r === false) {
         throw new Exception\RuntimeException($this->resource->error);
     }
     // dereference
     for ($i = 0, $count = count($this->statementBindValues['keys']); $i < $count; $i++) {
         $this->currentData[$this->statementBindValues['keys'][$i]] = $this->statementBindValues['values'][$i];
     }
     $this->currentComplete = true;
     $this->nextComplete = true;
     $this->position++;
     return true;
 }
开发者ID:musicsnap,项目名称:Yaf.Global.Library,代码行数:44,代码来源:Result.php

示例5: _execute

 /**
  * 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;
 }
开发者ID:jon9872,项目名称:zend-framework,代码行数:64,代码来源:Mysqli.php

示例6: execute

 /**
  * Executes a prepared statement.
  *
  * @param array $params OPTIONAL values to supply as input to statement parameters
  * @return void
  */
 public function execute(array $params = array())
 {
     // prepare for mysqli
     $sql = $this->_joinSql();
     $mysqli = $this->_connection->getConnection();
     $this->_stmt = $mysqli->prepare($sql);
     if ($this->_stmt === false || $mysqli->errno) {
         require_once 'Zend/Db/Statement/Mysqli/Exception.php';
         throw new Zend_Db_Statement_Mysqli_Exception("Mysqli prepare error: " . $mysqli->error);
     }
     // retain metadata
     $this->_meta = $this->_stmt->result_metadata();
     if ($this->_stmt->errno) {
         require_once 'Zend/Db/Statement/Mysqli/Exception.php';
         throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement metadata error for SQL = \"{$sql}\": " . $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[] = $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;
         }
         // bind to the result variables
         call_user_func_array(array($this->_stmt, 'bind_result'), $this->_values);
     }
     // 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
     $this->_stmt->execute();
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:49,代码来源:Mysqli.php

示例7: execute

 /**
  * {@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;
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:46,代码来源:MysqliStatement.php

示例8: preparedStatementFetch

 /**
  * (non-PHPdoc)
  * @see PreparedStatement::preparedStatementFetch()
  */
 public function preparedStatementFetch($msg = '')
 {
     if (!$this->stmt) {
         return false;
     }
     // first time, create an array of column names from the returned data set
     if (empty($this->preparedStatementResult)) {
         $this->resultFields = null;
         $this->preparedStatementResult = $this->stmt->result_metadata();
         if (is_object($this->preparedStatementResult)) {
             $this->resultFields = $this->preparedStatementResult->fetch_fields();
         } else {
             $this->preparedStatementResult = null;
             return false;
         }
         if (!empty($this->resultFields) && is_array($this->resultFields)) {
             $this->output_vars = $bound = array();
             foreach ($this->resultFields as $k => $field) {
                 $this->output_vars[$field->name] = null;
                 $bound[$k] =& $this->output_vars[$field->name];
             }
             call_user_func_array(array($this->stmt, "bind_result"), $bound);
         } else {
             $this->preparedStatementResult = null;
             return false;
         }
     }
     // Get the next results
     if ($this->stmt->fetch()) {
         $result = array();
         // FIXME: figure out how to avoid copying for each result
         // Right now copying is needed due to the fact that the bind_result
         // uses references so we can not give out the same array twice, as it will be
         // all referenced together and all have the data of the last row
         foreach ($this->output_vars as $k => $v) {
             $result[$k] = $v;
         }
         return $result;
     } else {
         return false;
     }
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:46,代码来源:MysqliPreparedStatement.php

示例9: _getResults

 /**
  * 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;
 }
开发者ID:NightWingStudios,项目名称:Nightshade,代码行数:26,代码来源:Query.php

示例10: _dynamicBindResults

 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;
 }
开发者ID:noikiy,项目名称:shopnc-minion,代码行数:38,代码来源:remoteDb.php

示例11: fetchAll

 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;
 }
开发者ID:michalkoczwara,项目名称:WebGoatPHP,代码行数:34,代码来源:mysqli.php

示例12: execute


//.........这里部分代码省略.........
  * @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;
 }
开发者ID:plan2net,项目名称:TYPO3.CMS,代码行数:101,代码来源:PreparedStatement.php

示例13: _fetch_results

 /**
  * Fetches the results from the MySQLi statement that was prepared and
  * executed. Will build an associative array containing all of the relevant
  * data from the query/statement that was executed.
  *
  * @param mysqli_stmt $statement The MySQLi statement to fetch the results
  *  from.
  * @return array Container for all information the statement stored after
  *  executing
  */
 protected static function _fetch_results($statement)
 {
     $params = array();
     $results = array();
     $metadata = $statement->result_metadata();
     while ($field = $metadata->fetch_field()) {
         $params[] =& $row[$field->name];
     }
     call_user_func_array(array($statement, 'bind_result'), $params);
     while ($statement->fetch()) {
         $tmp = array();
         foreach ($row as $key => $value) {
             if (is_string($value)) {
                 $value = stripslashes($value);
             }
             $tmp[$key] = $value;
         }
         $results[] = $tmp;
     }
     return $results;
 }
开发者ID:jugglinmike,项目名称:ae-framework,代码行数:31,代码来源:database.php

示例14: bindAssoc

 /**
  * @param \mysqli_stmt $stmt
  * @param array        $out
  */
 public static function bindAssoc($stmt, &$out)
 {
     $data = $stmt->result_metadata();
     if (!$data) {
         self::mySqlError('mysqli_stmt::result_metadata');
     }
     $fields = [];
     $out = [];
     while ($field = $data->fetch_field()) {
         $fields[] =& $out[$field->name];
     }
     $b = call_user_func_array([$stmt, 'bind_result'], $fields);
     if ($b === false) {
         self::mySqlError('mysqli_stmt::bind_result');
     }
     $data->free();
 }
开发者ID:setbased,项目名称:php-stratum,代码行数:21,代码来源:StaticDataLayer.php

示例15: importFromMysqli

 /**
  * Import table headers and data from \mysqli_stmt
  *
  * @param \mysqli_stmt $stmt
  */
 public function importFromMysqli(\mysqli_stmt $stmt)
 {
     $meta = $stmt->result_metadata();
     $this->_header = array();
     while (($column = $field = $meta->fetch_field()) !== false) {
         $this->_header[] = $column->name;
     }
     $result = $stmt->get_result();
     $this->_data = array();
     while ($row = $result->fetch_array(MYSQLI_NUM)) {
         $this->_data[] = $row;
     }
     // if options is empty we want to regenerate defaults
     if (count($this->_options) < 1) {
         $this->setOptions();
     }
     $this->_executeFormats();
 }
开发者ID:kehet,项目名称:php-cli-utils,代码行数:23,代码来源:Table.php


注:本文中的mysqli_stmt::result_metadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。