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


PHP mysqli_stmt类代码示例

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


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

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

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

示例12: execute

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

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

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

示例15: 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;未经允许,请勿转载。