Retrieves buffered result rows from a prepared statement as a mysqli_result.
The examples focus on the operation itself, including the important distinction: mysqli_stmt::fetch accesses bound output variables instead.
What It Does
Use the examples below to observe the behavior on a small dataset before extending it to application code.
Syntax and Return Value
Not an API method: use mysqli_stmt::get_result() instead
The displayed signature describes the API or identifies any correction or optional dependency. When a parameter is optional, supply it only when the task requires it.
Example 1: Basic Use
Important correction: mysqli::get_result() does not exist. The actual method is mysqli_stmt::get_result(), called on a prepared statement; mysqlnd is required.
<?php
$mysqli = new mysqli(getenv('DB_HOST') ?: '127.0.0.1', getenv('DB_USER') ?: 'app', getenv('DB_PASSWORD') ?: '', getenv('DB_NAME') ?: 'demo');
$mysqli->set_charset('utf8mb4');
$selectedId = 7;
$statement = $mysqli->prepare('SELECT email FROM users WHERE id = ?');
$statement->bind_param("i", $selectedId);
$statement->execute();
$result = $statement->get_result();
echo json_encode($result->fetch_assoc());
This example is meant for a configured application environment; output depends on the installed extension, external service, or database contents.
Example 2: Checking Behavior
Important correction: mysqli::get_result() does not exist. The actual method is mysqli_stmt::get_result(), called on a prepared statement; mysqlnd is required.
<?php
$mysqli = new mysqli(getenv('DB_HOST') ?: '127.0.0.1', getenv('DB_USER') ?: 'app', getenv('DB_PASSWORD') ?: '', getenv('DB_NAME') ?: 'demo');
$mysqli->set_charset('utf8mb4');
$selectedId = 12;
$statement = $mysqli->prepare('SELECT email FROM users WHERE id = ?');
$statement->bind_param("i", $selectedId);
$statement->execute();
$result = $statement->get_result();
echo json_encode($result->fetch_assoc());
This example is meant for a configured application environment; output depends on the installed extension, external service, or database contents.
Example 3: Practical Example
Important correction: mysqli::get_result() does not exist. The actual method is mysqli_stmt::get_result(), called on a prepared statement; mysqlnd is required.
<?php
$mysqli = new mysqli(getenv('DB_HOST') ?: '127.0.0.1', getenv('DB_USER') ?: 'app', getenv('DB_PASSWORD') ?: '', getenv('DB_NAME') ?: 'demo');
$mysqli->set_charset('utf8mb4');
$selectedId = 24;
$statement = $mysqli->prepare('SELECT email FROM users WHERE id = ?');
$statement->bind_param("i", $selectedId);
$statement->execute();
$result = $statement->get_result();
echo json_encode($result->fetch_assoc());
This example is meant for a configured application environment; output depends on the installed extension, external service, or database contents.
Important Behavior and Edge Cases
Requires mysqlnd and a statement that produces a result set; use bind_result where unsupported.
There is no method named mysqli::get_result(). Calling it on a mysqli connection raises an Error. Use mysqli_stmt::get_result() after preparing and executing the statement; mysqlnd is required.
Comparison with Related Approaches
| Approach | Difference |
|---|---|
| Mysqli::get_result | Retrieves buffered result rows from a prepared statement as a mysqli_result. |
| Related API or alternative | mysqli_stmt::fetch accesses bound output variables instead. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Ignoring the operation-specific limits | Requires mysqlnd and a statement that produces a result set; use bind_result where unsupported. |
| Confusing it with a related API | mysqli_stmt::fetch accesses bound output variables instead. |
Key Takeaways
- Retrieves buffered result rows from a prepared statement as a mysqli_result.
- Requires mysqlnd and a statement that produces a result set; use bind_result where unsupported.
- mysqli_stmt::fetch accesses bound output variables instead.
Use Mysqli::get_result when its documented behavior matches the problem. Test the relevant edge cases in your own runtime before deploying it.