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


PHP mysqli_stmt::fetch方法代码示例

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


在下文中一共展示了mysqli_stmt::fetch方法的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: 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

示例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: 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

示例5: fetch

 /**
  * Fetches a row from the result set.
  *
  * @param $style
  * @param $cursor
  * @param $offset
  * @return $data
  * @throws Zend_Db_Statement_Mysqli_Exception
  */
 public function fetch($style = null, $cursor = null, $offset = null)
 {
     // fetch the next result
     $retval = $this->_stmt->fetch();
     switch ($retval) {
         case null:
             // end of data
         // end of data
         case false:
             // error occurred
             $this->closeCursor();
             return $retval;
         default:
             // fallthrough
     }
     // make sure we have a fetch mode
     if ($style === null) {
         $style = $this->_fetchMode;
     }
     // dereference the result values, otherwise things like fetchAll()
     // return the same values for every entry (because of the reference).
     $values = array();
     foreach ($this->_values as $key => $val) {
         $values[] = $val;
     }
     // bind back to external references
     foreach ($this->_bindColumn as $key => &$val) {
         if (is_integer($key)) {
             // bind by column position
             // note that vals are 0-based, but cols are 1-based
             $val = $values[$key - 1];
         } else {
             // bind by column name
             $i = array_search($key, $this->_keys);
             $val = $values[$i];
         }
     }
     $data = false;
     switch ($style) {
         case Zend_Db::FETCH_NUM:
             $data = $values;
             break;
         case Zend_Db::FETCH_ASSOC:
             $data = array_combine($this->_keys, $values);
             break;
         case Zend_Db::FETCH_BOTH:
             $assoc = array_combine($this->_keys, $values);
             $data = array_merge($values, $assoc);
             break;
         case Zend_Db::FETCH_OBJ:
             $data = (object) array_combine($this->_keys, $values);
             break;
         default:
             require_once 'Zend/Db/Statement/Mysqli/Exception.php';
             throw new Zend_Db_Statement_Mysqli_Exception("Invalid fetch mode specified");
             break;
     }
     return $data;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:68,代码来源:Mysqli.php

示例6: fetch_row

 public function fetch_row()
 {
     $result = $this->statement->fetch();
     if (false === $result) {
         throw new BeeHub_MySQL(self::mysqli()->error, self::mysqli()->errno);
     }
     return $result ? $this->results_array : null;
 }
开发者ID:niekbosch,项目名称:BeeHub,代码行数:8,代码来源:BeeHub_DB.php

示例7: fetch

 /**
  * Fetches a row from the result set.
  *
  * @param int $style  OPTIONAL Fetch mode for this fetch operation.
  * @param int $cursor OPTIONAL Absolute, relative, or other.
  * @param int $offset OPTIONAL Number for absolute or relative cursors.
  * @return mixed Array, object, or scalar depending on fetch mode.
  * @throws Zend_Db_Statement_Mysqli_Exception
  */
 public function fetch($style = null, $cursor = null, $offset = null)
 {
     if (!$this->_stmt) {
         return false;
     }
     // fetch the next result
     $retval = $this->_stmt->fetch();
     switch ($retval) {
         case null:
             // end of data
         // end of data
         case false:
             // error occurred
             $this->_stmt->reset();
             return $retval;
         default:
             // fallthrough
     }
     // make sure we have a fetch mode
     if ($style === null) {
         $style = $this->_fetchMode;
     }
     // dereference the result values, otherwise things like fetchAll()
     // return the same values for every entry (because of the reference).
     $values = array();
     foreach ($this->_values as $key => $val) {
         $values[] = $val;
     }
     $row = false;
     switch ($style) {
         case Zend_Db::FETCH_NUM:
             $row = $values;
             break;
         case Zend_Db::FETCH_ASSOC:
             $row = array_combine($this->_keys, $values);
             break;
         case Zend_Db::FETCH_BOTH:
             $assoc = array_combine($this->_keys, $values);
             $row = array_merge($values, $assoc);
             break;
         case Zend_Db::FETCH_OBJ:
             $row = (object) array_combine($this->_keys, $values);
             break;
         case Zend_Db::FETCH_BOUND:
             $assoc = array_combine($this->_keys, $values);
             $row = array_merge($values, $assoc);
             return $this->_fetchBound($row);
             break;
         default:
             /**
              * @see Zend_Db_Statement_Mysqli_Exception
              */
             require_once 'Zend/Db/Statement/Mysqli/Exception.php';
             throw new Zend_Db_Statement_Mysqli_Exception("Invalid fetch mode '{$style}' specified");
             break;
     }
     return $row;
 }
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:67,代码来源:Mysqli.php

示例8: _fetch

 /**
  * @return boolean|array
  */
 private function _fetch()
 {
     $ret = $this->_stmt->fetch();
     if (true === $ret) {
         $values = array();
         foreach ($this->_rowBindedValues as $v) {
             $values[] = $v;
         }
         return $values;
     }
     return $ret;
 }
开发者ID:doctrine,项目名称:dbal,代码行数:15,代码来源:MysqliStatement.php

示例9: nextRecord

 public function nextRecord()
 {
     // Skip data if out of data
     if (!$this->statement->fetch()) {
         return false;
     }
     // Dereferenced row
     $row = array();
     foreach ($this->boundValues as $key => $value) {
         $row[$key] = $value;
     }
     return $row;
 }
开发者ID:nicocin,项目名称:silverstripe-framework,代码行数:13,代码来源:MySQLStatement.php

示例10: _fetch

 /**
  * @return boolean|array
  */
 private function _fetch()
 {
     $ret = $this->_stmt->fetch();
     if (true === $ret) {
         $values = array();
         foreach ($this->_rowBindedValues as $v) {
             // Mysqli converts them to a scalar type it can fit in.
             $values[] = null === $v ? null : (string) $v;
         }
         return $values;
     }
     return $ret;
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:16,代码来源:MysqliStatement.php

示例11: caricaIndirizzoDaStmt

 /**
  * Carica un indirizzo eseguendo un prepared statement
  * @param mysqli_stmt $stmt
  * @return null
  */
 public function caricaIndirizzoDaStmt(mysqli_stmt $stmt)
 {
     if (!$stmt->execute()) {
         error_log("[caricaIndirizzoDaStmt] impossibile" . " eseguire lo statement");
         return null;
     }
     $row = array();
     $bind = $stmt->bind_result($row['id'], $row['destinatario'], $row['via_num'], $row['citta'], $row['provincia'], $row['cap'], $row['telefono']);
     if (!$bind) {
         error_log("[caricaIndirizzoDaStmt] impossibile" . " effettuare il binding in output");
         return null;
     }
     if (!$stmt->fetch()) {
         return null;
     }
     $stmt->close();
     return self::creaIndirizzoDaArray($row);
 }
开发者ID:Artorias91,项目名称:Progetto-AMM,代码行数:23,代码来源:IndirizzoFactory.php

示例12: array

 /**
  * Carica una lista di articoli eseguendo un prepared statement
  * @param mysqli_stmt $stmt
  * @return null
  */
 public function &caricaArticoliDaStmt(mysqli_stmt $stmt)
 {
     $articoli = array();
     if (!$stmt->execute()) {
         error_log("[caricaArticoliDaStmt] impossibile" . " eseguire lo statement");
         return null;
     }
     $row = array();
     $bind = $stmt->bind_result($row['id'], $row['size'], $row['qty'], $row['prezzo'], $row['pizza_id']);
     if (!$bind) {
         error_log("[caricaArticoliDaStmt] impossibile" . " effettuare il binding in output");
         return null;
     }
     while ($stmt->fetch()) {
         $articoli[] = self::creaArticoloDaArray($row);
     }
     $stmt->close();
     return $articoli;
 }
开发者ID:Artorias91,项目名称:Progetto-AMM,代码行数:24,代码来源:ArticoloFactory.php

示例13: 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

示例14: _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

示例15: _dynamicBindResults

 /**
  * 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();
     $row = array();
     while ($field = $meta->fetch_field()) {
         $row[$field->name] = null;
         $parameters[] =& $row[$field->name];
     }
     call_user_func_array(array($stmt, 'bind_result'), $parameters);
     while ($stmt->fetch()) {
         $x = array();
         foreach ($row as $key => $val) {
             $x[$key] = $val;
         }
         array_push($results, $x);
     }
     return $results;
 }
开发者ID:AugustoAngeletti,项目名称:erepublik,代码行数:28,代码来源:MysqliDb.php


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