class mysqli_stmt (View source)

Represents a prepared statement.

Properties

int $affected_rows
int $insert_id
int $num_rows
int $param_count
int $field_count
int $errno
string $error
array $error_list
string $sqlstate
string $id

Methods

__construct(mysqli $mysql, string $query)

mysqli_stmt constructor

int
attr_get(int $attribute)

Used to get the current value of a statement attribute

bool
attr_set(int $attribute, int $value)

Used to modify the behavior of a prepared statement

bool
bind_param(string $types, mixed $var1, mixed ...$_)

Binds variables to a prepared statement as parameters

bool
bind_result(mixed $var1, mixed ...$_)

Binds variables to a prepared statement for result storage

bool
close()

Closes a prepared statement

void
data_seek(int $offset)

Seeks to an arbitrary row in statement result set

bool
execute(array|null $params = null)

Executes a prepared statement

bool|null
fetch()

Fetch results from a prepared statement into the bound variables

mysqli_warning|false
get_warnings()

Get result of SHOW WARNINGS

mysqli_result|false
result_metadata()

Returns result set metadata from a prepared statement

bool
more_results()

Check if there are more query results from a multiple query

bool
next_result()

Reads the next result from a multiple query

string|int
num_rows()

Return the number of rows in statements result set

bool
send_long_data(int $param_num, string $data)

Send data in blocks

stmt()

No documentation available

void
free_result()

Frees stored result memory for the given statement handle

bool
reset()

Resets a prepared statement

bool
prepare(string $query)

Prepare an SQL statement for execution

bool
store_result()

Stores a result set in an internal buffer

mysqli_result|false
get_result()

Gets a result set from a prepared statement as a mysqli_result object

Details

__construct(mysqli $mysql, string $query)

mysqli_stmt constructor

Parameters

mysqli $mysql
string $query [optional]

int attr_get(int $attribute)

Used to get the current value of a statement attribute

Parameters

int $attribute

The attribute that you want to get.

Return Value

int

Returns the value of the attribute.

bool attr_set(int $attribute, int $value)

Used to modify the behavior of a prepared statement

Parameters

int $attribute

The attribute that you want to set. It can have one of the following values:

Attribute values
Character Description
MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH If set to 1, causes mysqli_stmt_store_result to update the metadata MYSQL_FIELD->max_length value.
MYSQLI_STMT_ATTR_CURSOR_TYPE Type of cursor to open for statement when mysqli_stmt_execute is invoked. mode can be MYSQLI_CURSOR_TYPE_NO_CURSOR (the default) or MYSQLI_CURSOR_TYPE_READ_ONLY.
MYSQLI_STMT_ATTR_PREFETCH_ROWS Number of rows to fetch from server at a time when using a cursor. mode can be in the range from 1 to the maximum value of unsigned long. The default is 1.

If you use the MYSQLI_STMT_ATTR_CURSOR_TYPE option with MYSQLI_CURSOR_TYPE_READ_ONLY, a cursor is opened for the statement when you invoke mysqli_stmt_execute. If there is already an open cursor from a previous mysqli_stmt_execute call, it closes the cursor before opening a new one. mysqli_stmt_reset also closes any open cursor before preparing the statement for re-execution. mysqli_stmt_free_result closes any open cursor.

If you open a cursor for a prepared statement, mysqli_stmt_store_result is unnecessary.

int $value

The value to assign to the attribute.

Return Value

bool

bool bind_param(string $types, mixed $var1, mixed ...$_)

Binds variables to a prepared statement as parameters

Parameters

string $types

A string that contains one or more characters which specify the types for the corresponding bind variables:

Type specification chars
Character Description
i corresponding variable has type integer
d corresponding variable has type double
s corresponding variable has type string
b corresponding variable is a blob and will be sent in packets

mixed $var1

The number of variables and length of string types must match the parameters in the statement.

mixed ...$_ [optional]

Return Value

bool

true on success or false on failure.

bool bind_result(mixed $var1, mixed ...$_)

Binds variables to a prepared statement for result storage

Parameters

mixed $var1

The variable to be bound.

mixed ...$_

The variables to be bound.

Return Value

bool

true on success or false on failure.

bool close()

Closes a prepared statement

Return Value

bool

true on success or false on failure.

void data_seek(int $offset)

Seeks to an arbitrary row in statement result set

Parameters

int $offset

Must be between zero and the total number of rows minus one (0.. mysqli_stmt_num_rows - 1).

Return Value

void

bool execute(array|null $params = null)

Executes a prepared statement

Parameters

array|null $params

[optional] An optional list array with as many elements as there are bound parameters in the SQL statement being executed. Each value is treated as a string.

Return Value

bool

true on success or false on failure.

bool|null fetch()

Fetch results from a prepared statement into the bound variables

Return Value

bool|null

mysqli_warning|false get_warnings()

Get result of SHOW WARNINGS

Return Value

mysqli_warning|false

mysqli_result|false result_metadata()

Returns result set metadata from a prepared statement

Return Value

mysqli_result|false

a result object or false if an error occurred.

bool more_results()

Check if there are more query results from a multiple query

Return Value

bool

bool next_result()

Reads the next result from a multiple query

Return Value

bool

string|int num_rows()

Return the number of rows in statements result set

Return Value

string|int

An integer representing the number of rows in result set.

bool send_long_data(int $param_num, string $data)

Send data in blocks

Parameters

int $param_num

Indicates which parameter to associate the data with. Parameters are numbered beginning with 0.

string $data

A string containing data to be sent.

Return Value

bool

true on success or false on failure.

stmt()

No documentation available

void free_result()

Frees stored result memory for the given statement handle

Return Value

void

bool reset()

Resets a prepared statement

Return Value

bool

true on success or false on failure.

bool prepare(string $query)

Prepare an SQL statement for execution

Parameters

string $query

The query, as a string. It must consist of a single SQL statement.

The SQL statement may contain zero or more parameter markers represented by question mark (?) characters at the appropriate positions.

The markers are legal only in certain places in SQL statements. For example, they are permitted in the VALUES() list of an INSERT statement (to specify column values for a row), or in a comparison with a column in a WHERE clause to specify a comparison value.

However, they are not permitted for identifiers (such as table or column names), or to specify both operands of a binary operator such as the = equal sign. The latter restriction is necessary because it would be impossible to determine the parameter type. In general, parameters are legal only in Data Manipulation Language (DML) statements, and not in Data Definition Language (DDL) statements.

Return Value

bool

true on success or false on failure.

bool store_result()

Stores a result set in an internal buffer

Return Value

bool

true on success or false on failure.

mysqli_result|false get_result()

Gets a result set from a prepared statement as a mysqli_result object

Return Value

mysqli_result|false

Returns a resultset or FALSE on failure