Current Location: Home> Function Categories> mysqli::execute_query

mysqli::execute_query

(mysqli_execute_query)Prepares, binds parameters, and executes SQL statement
Name:mysqli::execute_query
Category:MySQLi
Programming Language:php
One-line Description:Query, as a string. It must consist of a single SQL statement. Prepare, bind parameters and execute SQL statements

Applicable to PHP version (PHP 8 >= 8.2.0)


illustrate

Object-oriented style

 public mysqli::execute_query(string $query, ?array $params = null): mysqli_result|bool
Process style

 mysqli_execute_query(mysqli $mysql, string $query, ?array $params = null): mysqli_result|bool
Prepare SQL queries, bind parameters and execute queries. The mysqli::execute_query() method is a shortcut to mysqli::prepare(), mysqli_stmt::bind_param(), mysqli_stmt::execute() and mysqli_stmt::get_result().

A statement template can contain zero or more question marks (?) parameter marks - also known as placeholders. Parameter values ​​must be provided as array using params parameter.

Preprocessing statements are created at the bottom, but are never exposed outside the function. It is impossible to access the properties of a statement like accessing the mysqli_stmt object. Due to this limitation, the status information is copied into the mysqli object and its methods can be used, such as mysqli_affected_rows() or mysqli_error().

Notice

If the statement passed to mysqli_execute_query() is longer than the server's max_allowed_packet, the returned error code will vary depending on the operating system. The behavior is as follows:

Return error code 1153 on Linux. The error message means that the resulting packet is larger than the max_allowed_packet bytes.

Returns error code 2006 on Windows. This error message indicates that the server has disappeared.

parameter
mysql
Procedural style only: a mysqli object returned by mysqli_connect() or mysqli_init().

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

SQL statements can contain zero or more parameter marks represented by question marks (?) characters in appropriate locations.

Notice:

These tags are only legal in certain places in SQL statements. For example, they are allowed to be used in the VALUES() list of the INSERT statement (specifying column values ​​for a row), or they are allowed to specify comparison values ​​when compared with columns in the WHERE clause. However, they are not allowed to be used for identifiers (such as table or column names).

params
An optional list array with as many elements as the number of bound parameters in the SQL statement being executed. Each value is treated as a string.

Similar Functions
Popular Articles