PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

mysqli_query

Tags: PHP 5.x PHP 7.x PHP 8.x

mysqli_query — Performs a query on the database.

Description

mysqli_query(
    mysqli $mysql,
string $query,
int $result_mode = MYSQLI_STORE_RESULT
): mysqli_result|bool
Performs a query against the database. For non-DML queries (not INSERT, UPDATE or DELETE), this function is similar to calling mysqli_real_query() followed by either mysqli_use_result() or mysqli_store_result().

Parameters

mysql
Procedural style only: A mysqli object returned by mysqli_connect() or mysqli_init()
query
The query string.
result_mode
The result mode can be one of 3 constants indicating how the result will be returned from the MySQL server.
MYSQLI_STORE_RESULT (default) - returns a mysqli_result object with buffered result set.
MYSQLI_USE_RESULT - returns a mysqli_result object with unbuffered result set. As long as there are pending records waiting to be fetched, the connection line will be busy and all subsequent calls will return error Commands out of sync. To avoid the error all records must be fetched from the server or the result set must be discarded by calling mysqli_free_result().
MYSQLI_ASYNC (available with mysqlnd) - the query is performed asynchronously and no result set is immediately returned. mysqli_poll() is then used to get results from such queries. Used in combination with either MYSQLI_STORE_RESULT or MYSQLI_USE_RESULT constant.

Return Values

Returns false on failure. For successful queries which produce a result set, such as SELECT, SHOW, DESCRIBE or EXPLAIN, mysqli_query() will return a mysqli_result object. For other successful queries, mysqli_query() will return true.

mysqli_query - New snippets