The mysqli_stmt class
(PHP 5)
Introduction
Represents a prepared statement.
Class synopsis
mysqli_stmt
{
/* Properties */
int $affected_rows;
int $errno;
array $error_list;
string $error;
int $field_count;
int $insert_id;
int $num_rows;
int $param_count;
string $sqlstate;
/* Methods */
}Table of Contents
- mysqli_stmt::$affected_rows — Returns the total number of rows changed, deleted, or inserted by the last executed statement
- mysqli_stmt::attr_get — Used to get the current value of a statement attribute
- mysqli_stmt::attr_set — Used to modify the behavior of a prepared statement
- mysqli_stmt::bind_param — Binds variables to a prepared statement as parameters
- mysqli_stmt::bind_result — Binds variables to a prepared statement for result storage
- mysqli_stmt::close — Closes a prepared statement
- mysqli_stmt::data_seek — Seeks to an arbitrary row in statement result set
- mysqli_stmt::$errno — Returns the error code for the most recent statement call
- mysqli_stmt::$error_list — Returns a list of errors from the last statement executed
- mysqli_stmt::$error — Returns a string description for last statement error
- mysqli_stmt::execute — Executes a prepared Query
- mysqli_stmt::fetch — Fetch results from a prepared statement into the bound variables
- mysqli_stmt::$field_count — Returns the number of field in the given statement
- mysqli_stmt::free_result — Frees stored result memory for the given statement handle
- mysqli_stmt::get_result — Gets a result set from a prepared statement
- mysqli_stmt::get_warnings — Get result of SHOW WARNINGS
- mysqli_stmt::$insert_id — Get the ID generated from the previous INSERT operation
- mysqli_stmt::more_results — Check if there are more query results from a multiple query
- mysqli_stmt::next_result — Reads the next result from a multiple query
- mysqli_stmt::$num_rows — Return the number of rows in statements result set
- mysqli_stmt::$param_count — Returns the number of parameter for the given statement
- mysqli_stmt::prepare — Prepare an SQL statement for execution
- mysqli_stmt::reset — Resets a prepared statement
- mysqli_stmt::result_metadata — Returns result set metadata from a prepared statement
- mysqli_stmt::send_long_data — Send data in blocks
- mysqli_stmt::$sqlstate — Returns SQLSTATE error from previous statement operation
- mysqli_stmt::store_result — Transfers a result set from a prepared statement
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MySQL Drivers and Plugins
- Введение
- Краткий обзор
- Краткое руководство
- Установка и настройка
- Расширение mysqli и постоянные соединения
- Предопределенные константы
- Notes
- Основная информация о функциях расширения MySQLi
- Examples
- Класс mysqli
- The mysqli_stmt class
- The mysqli_result class
- Класс mysqli_driver
- Класс mysqli_warning
- The mysqli_sql_exception class
- Синонимы и устаревшие Функции Mysqli
- Список изменений
Коментарии
The prototype of the mysqli_stmt constructor is mysqli_stmt::__construct(mysqli $link, $query);
To extend mysqli_stmt, do
class myStmt extends mysqli_stmt {
public function __construct($link, $query) {
parent::__construct($link, $query);
}
}
class myI extends mysqli {
public function prepare($query) {
return new myStmt($this, $query);
}
}
http://blog.myhat.de/2007/06/26/pdo-and-extending-mysqli/ has further infos including how to extend mysqli_result
<?php
class MySQL
{
protected $mysql;
function __construct()
{
//Get MySQL config values from config.ini file
if($config = parse_ini_file("../config.ini"))
{
// Obtener los valores del fichero de configuración config.ini
$ip = $config["ip"];
$user = $config["usuario"];
$pass = $config["password"];
$bd = $config["bd"];
//Connection between a database and php
$this->mysql = new mysqli($ip, $user, $pass, $bd);
}
}
function setResultQuery($query, $param)
{
$array = NULL;
if(!$this->mysql->connect_errno)
{
$stmt = $this->setStatement($query, $param);
try
{
if($stmt != NULL)
{
if($stmt->execute())
{
//Obtener resultados
$stmt->store_result();
$variables = array();
$data = array();
$meta = $stmt->result_metadata();
while($field = $meta->fetch_field())
{
$variables[] = &$data[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $variables);
$i=0;
while($stmt->fetch())
{
$array[$i] = array();
foreach($data as $k=>$v)
$array[$i][$k] = $v;
$i++;
}
$stmt->close();
}
}
}catch(Exception $e){
$array = FALSE;
}
}
return $array;
}
function setStatement($query, $param)
{
try
{
$stmt = $this->mysql->prepare($query);
$ref = new ReflectionClass('mysqli_stmt');
if(count($param) != 0)
{
$method = $ref->getMethod('bind_param');
$method->invokeArgs($stmt, $param);
}
}catch(Exception $e){
if($stmt != null)
{
$stmt->close();
}
}
return $stmt;
}
function setNoResultQuery($query, $param)
{
$validation = FALSE;
if(!$this->mysql->connect_errno)
{
try
{
$stmt = $this->setStatement($query, $param);
if($stmt != null)
{
if($stmt->execute())
{
$stmt->close();
$validacion = TRUE;
}
}
}catch(Exception $e){
$validation = FALSE;
}
}
return $validation;
}
function __destruct()
{
$this->mysql->close();
}
}
?>