In PHP, mysqli_execute_query() prepares, binds, executes and (for SELECT) returns a result in one step; it is available in PHP 8.2 and newer.
Object-oriented style uses $mysqli->execute_query($query, $params). Pass a SQL string with ? placeholders and an optional list of parameters. It is a convenience helper around prepare + bind + execute + get_result.
Syntax
Call mysqli_execute_query() with the values you need. Start with this line.
PHP
$result = mysqli_execute_query($mysqli, "SELECT id, name FROM products WHERE id = ?", [10]);
Call
What it does
mysqli_execute_query($mysqli, "SELECT name FROM products WHERE id = ?", [10])
Runs a parameterized SELECT and returns a result.
$mysqli->execute_query("UPDATE products SET stock = ? WHERE id = ?", [5, 10])
OO form for a write query; returns true/false.
mysqli_execute_query($mysqli, "SELECT 1")
Runs SQL with no parameters.
Requires PHP 8.2+. For older PHP, use mysqli_prepare() and bind_param() yourself. On success, SELECT-style statements return mysqli_result; other statements return true.
Optional. List of values to bind, or null when there are no placeholders.
Return Value
Return Value
Description
mysqli_result|bool
A result object for result-producing queries, true for successful non-result queries, or false on failure.
PHP Examples
Example 1 — Parameterized SELECT in One Call
Fetch one product by id. Sample output when connected to a demo database (PHP 8.2+).
PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
mysqli_set_charset($mysqli, "utf8mb4");
$result = mysqli_execute_query(
$mysqli,
"SELECT name FROM products WHERE id = ?",
[10]
);
$row = mysqli_fetch_assoc($result);
echo $row["name"], PHP_EOL;
mysqli_close($mysqli);
Output
Notebook
How It Works
execute_query prepares and runs the SQL with one bound id.
A mysqli_result is returned for the SELECT.
fetch_assoc() reads the demo row.
Sample output prints Notebook.
Example 2 — Object Style Update
Update stock with bound parameters and check success.
PHP
<?php
$mysqli = new mysqli("localhost", "demo", "secret", "shop");
$mysqli->set_charset("utf8mb4");
$ok = $mysqli->execute_query(
"UPDATE products SET stock = ? WHERE id = ?",
[3, 10]
);
echo $ok ? "updated" : "failed", PHP_EOL;
echo "affected=", $mysqli->affected_rows, PHP_EOL;
$mysqli->close();
Output
updated
affected=1
How It Works
OO execute_query binds stock and id.
A non-SELECT returns true on success.
affected_rows reports how many rows changed.
Sample output shows one updated row.
Example 3 — Multiple Placeholders
Filter with two bound values without string concatenation.
PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
mysqli_set_charset($mysqli, "utf8mb4");
$result = mysqli_execute_query(
$mysqli,
"SELECT name FROM products WHERE category = ? AND price <= ? ORDER BY name",
["books", 12.5]
);
while ($row = mysqli_fetch_assoc($result)) {
echo $row["name"], PHP_EOL;
}
mysqli_close($mysqli);
Output
Notebook
Pencil Set
How It Works
Two placeholders receive category and price.
Values stay out of the SQL string text.
The while loop prints each matching name.
Sample output when connected to a demo database lists two products.
Frequently Asked Questions
In PHP 8.2+ it prepares a statement, binds optional parameters, executes it, and returns a result for SELECT-style SQL (or true for other successful statements).
No. It was added in PHP 8.2. On older versions use mysqli_prepare(), bind_param() and execute() instead.
Call $mysqli->execute_query($query, $params). Behavior matches the procedural function.
Parameters are sent separately from the SQL template, so user values cannot change the statement structure the way string concatenation can.
true on success (and false on failure). Use affected_rows or insert_id afterward when you need those details.