當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。