• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP mysqli_stmt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

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


示例2: doLoginWithPostData

 private function doLoginWithPostData()
 {
     // check login form contents
     if (empty($_POST['email'])) {
         $this->errors[] = "Email field was empty.";
     } else {
         if (empty($_POST['password'])) {
             $this->errors[] = "Password field was empty.";
         } else {
             if (!empty($_POST['email']) && !empty($_POST['password'])) {
                 $this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
                 // change character set to utf8 and check it
                 if (!$this->db_connection->set_charset("utf8")) {
                     $this->errors[] = $this->db_connection->error;
                 }
                 // if no connection errors (= working database connection)
                 if (!$this->db_connection->connect_errno) {
                     // escape the POST stuff
                     $email = $this->db_connection->real_escape_string($_POST['email']);
                     // database query, getting all the info of the selected user (allows login via email address in the
                     // username field)
                     $sql = new mysqli_stmt($this->db_connection, "SELECT id, first_name, last_name, email, password, privilege FROM users WHERE email = ?;");
                     $sql->bind_param("s", $_POST['email']);
                     $sql->execute();
                     $result_of_login_check = $sql->get_result();
                     // if this user exists
                     if ($result_of_login_check->num_rows == 1) {
                         // get result row (as an object)
                         $result_row = $result_of_login_check->fetch_object();
                         // using PHP 5.5's password_verify() function to check if the provided password fits
                         // the hash of that user's password
                         if (password_verify($_POST['password'], $result_row->password)) {
                             // write user data into PHP SESSION (a file on your server)
                             $_SESSION['id'] = $result_row->id;
                             $_SESSION['first_name'] = $result_row->first_name;
                             $_SESSION['last_name'] = $result_row->last_name;
                             $_SESSION['email'] = $result_row->email;
                             //                        $_SESSION['privilege'] = $result_row->privilege;
                             $_SESSION['user_login_status'] = 1;
                             $this->messages[] = "You have logged in successfully!";
                         } else {
                             $this->errors[] = "Wrong password. Try again.";
                         }
                     } else {
                         $this->errors[] = "This user does not exist.";
                     }
                 } else {
                     $this->errors[] = "Database connection problem.";
                 }
             }
         }
     }
 }
开发者ID:spiotr12,项目名称:WonderBlog,代码行数:53,代码来源:Login.class.php


示例3: close

 /**
  * 
  * 关闭 stmt result mysqli的函数,传入这三个东西就行
  * @param mysqli,stmt,result
  */
 static function close(mysqli $mysqli = null, mysqli_stmt $stmt = null, mysqli_result $result = null)
 {
     if ($result != null) {
         $result->free();
     }
     if ($stmt != null) {
         $stmt->close();
     }
     if ($mysqli != null) {
         $mysqli->close();
     }
 }
开发者ID:reducm,项目名称:JASEnglish,代码行数:17,代码来源:db.class.php


示例4: free

 /**
  * 释放资源
  *
  * @return void
  */
 public function free()
 {
     if ($this->prepare instanceof \mysqli_stmt) {
         $this->prepare->close();
         $this->prepare = null;
     }
 }
开发者ID:qazzhoubin,项目名称:emptyphp,代码行数:12,代码来源:MysqlStmt.php


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


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


示例7: rewind

 /**
  * Rewind
  */
 public function rewind()
 {
     if ($this->position !== 0) {
         if ($this->isBuffered === false) {
             throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations');
         }
     }
     $this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt
     $this->currentComplete = false;
     $this->position = 0;
 }
开发者ID:necrogami,项目名称:zf2,代码行数:14,代码来源:Result.php


示例8: rewind

 /**
  * Rewind
  * 
  */
 public function rewind()
 {
     $this->currentComplete = false;
     $this->position = 0;
     if ($this->resource instanceof \mysqli_stmt) {
         //$this->resource->reset();
     } else {
         $this->resource->data_seek(0);
         // works for both mysqli_result & mysqli_stmt
     }
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:15,代码来源:Result.php


示例9: freeResult

 /**
  * Method to free up the memory used for the result set.
  *
  * @param   mixed  $cursor  The optional result set cursor from which to fetch the row.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function freeResult($cursor = null)
 {
     $this->executed = false;
     if ($cursor instanceof \mysqli_result) {
         $cursor->free_result();
     }
     if ($this->prepared instanceof \mysqli_stmt) {
         $this->prepared->close();
         $this->prepared = null;
     }
 }
开发者ID:jbanety,项目名称:database,代码行数:20,代码来源:MysqliDriver.php


示例10: fetchAll

 /**
  * @return array
  * @throws \Exception
  */
 public function fetchAll()
 {
     $results = [$this->translator->trans('sorry', array(), 'messages'), $this->translator->trans('wrong_query_execution', array(), 'messages')];
     do {
         if (isset($this->connection->field_count) && !$this->connection->field_count) {
             if (strlen($this->connection->error) > 0) {
                 $error = $this->connection->error;
                 if ($this->connection->errno === 2014) {
                     // Repair all tables of the test database
                     $this->logger->error('[CONNECTION] ' . $error);
                 } else {
                     $this->logger->info('[CONNECTION] ' . $error);
                 }
                 throw new \Exception($error);
             } else {
                 $this->lastResults = self::RESULTS_NONE;
                 $results[1] = $this->translator->trans('no_record', array(), 'messages');
                 if (!is_null($this->statement) && $this->statement instanceof \mysqli_stmt) {
                     /**
                      * @see http://stackoverflow.com/a/25377031/2820730 about using \mysqli and xdebug
                      */
                     $this->statement->close();
                     unset($this->statement);
                 }
             }
         } else {
             $queryResult = $this->lastResults;
             /**
              * @var \mysqli_result $queryResult
              */
             if (is_object($queryResult) && $queryResult instanceof \mysqli_result) {
                 $results = [];
                 while ($result = $queryResult->fetch_array(MYSQLI_ASSOC)) {
                     if (!is_null($result)) {
                         $results[] = $result;
                     }
                 }
             }
         }
         $this->queryCount--;
     } while ($this->queryCount > 0);
     return $results;
 }
开发者ID:WeavingTheWeb,项目名称:devobs,代码行数:47,代码来源:Connection.php


示例11: array

 public function &creaAlbumDaStmt(mysqli_stmt $stmt)
 {
     $album = array();
     if (!$stmt->execute()) {
         error_log("[creaAlbumDaStmt] impossibile" . " eseguire lo statement");
         return null;
     }
     $row = array();
     $bind = $stmt->bind_result($row['id'], $row['nome'], $row['autore'], $row['prezzo']);
     if (!$bind) {
         error_log("[creaAlbumDaStmt] impossibile" . " effettuare il binding in output");
         return null;
     }
     while ($stmt->fetch()) {
         $album = self::creaAlbumDaArray($row);
     }
     $stmt->close();
     return $album;
 }
开发者ID:headlessdoll,项目名称:Amm2015,代码行数:19,代码来源:AlbumFactory.php


示例12: getFetchArrays

 /**
  * 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;
 }
开发者ID:musicsnap,项目名称:Yaf.Global.Library,代码行数:24,代码来源:Result.php


示例13: _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();
     // 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;
 }
开发者ID:aanyun,项目名称:online-contract-signing,代码行数:35,代码来源:MysqliDb.php


示例14: caricaClienteDaStmt

 /**
  * Carica un cliente eseguendo un prepared statement
  * @param mysqli_stmt $stmt
  * @return null
  */
 private function caricaClienteDaStmt(mysqli_stmt $stmt)
 {
     if (!$stmt->execute()) {
         error_log("[caricaClienteDaStmt] impossibile" . " eseguire lo statement");
         return null;
     }
     $row = array();
     $bind = $stmt->bind_result($row['id'], $row['username'], $row['password'], $row['email'], $row['nome'], $row['cognome'], $row['indirizzo']);
     if (!$bind) {
         error_log("[caricaClienteDaStmt] impossibile" . " effettuare il binding in output");
         return null;
     }
     if (!$stmt->fetch()) {
         return null;
     }
     $stmt->close();
     return self::creaClienteDaArray($row);
 }
开发者ID:Artorias91,项目名称:Progetto-AMM,代码行数:23,代码来源:UserFactory.php


示例15: preparedStatementClose

 public function preparedStatementClose()
 {
     if ($this->stmt) {
         $this->stmt->close();
         $this->stmt = null;
     }
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:7,代码来源:MysqliPreparedStatement.php


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


示例17: execute

 public function execute()
 {
     if (count($this->mbind_params)) {
         $this->mbind_param_do();
     }
     return parent::execute();
 }
开发者ID:jonca44,项目名称:pdf-mailmerge,代码行数:7,代码来源:iSQL.php


示例18: executar

 /**
  * executar
  * Recebe os dados, monta o bind_param e executa.
  * 
  * @param array
  * @throws Exception
  */
 protected function executar(array $dados)
 {
     /** @var array */
     $params = $this->prepararDados($dados);
     /** Passa os paramentros ao bind_param */
     if (count($dados) > 0) {
         if ($this->stmt) {
             call_user_func_array(array($this->stmt, 'bind_param'), $this->makeValuesReferenced($params));
         } else {
             throw new Exception("Erro ao executar \"{$this->mysqli->error}\"", $this->mysqli->errno);
         }
     }
     /** Executa a consulta e verifica se ocorreu algum erro */
     if (!$this->stmt->execute()) {
         throw new Exception("Erro ao executar: (" . $this->stmt->error . ") ", $this->stmt->errno);
     }
     /** Preenche o array de dados caso haja algum retorno */
     $this->result = array();
     $r = $this->stmt->get_result();
     if ($r) {
         while ($row = $r->fetch_assoc()) {
             $this->result[] = $row;
         }
     }
     /** Fecha o stamtment e a conexao com o banco */
     $this->stmt->close();
     $this->mysqli->close();
 }
开发者ID:Giselly,项目名称:AVAWEB_Responsivo,代码行数:35,代码来源:ConexaoDAO.class.php


示例19: execute

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


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP mysqlquery类代码示例发布时间:2022-05-23
下一篇:
PHP mysqli_result类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap