mysqli_stmt::store_result

mysqli_stmt_store_result

Stores a result set in an internal buffer

&reftitle.description;

&style.oop;

public `bool` `mysqli_stmt::store_result`

&style.procedural;

`bool` `mysqli_stmt_store_result` `mysqli_stmt` `statement`

This function should be called for queries that successfully produce a result set (e.g. `SELECT, SHOW, DESCRIBE, EXPLAIN`) only if the complete result set needs to be buffered in PHP. Each subsequent `mysqli_stmt_fetch` call will return buffered data.

It is unnecessary to call `mysqli_stmt_store_result` for other queries, but if you do, it will not harm or cause any notable performance loss in all cases. You can detect whether the query produced a result set by checking if `mysqli_stmt_result_metadata` returns &false;.

&reftitle.parameters;

&mysqli.stmt.description;
&reftitle.returnvalues;

&return.success;

&reftitle.errors; &mysqli.conditionalexception;
&reftitle.examples;

### &style.oop;

    <?php

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world");

    $query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
    $stmt = $mysqli->prepare($query);
    $stmt->execute();

    /* store the result in an internal buffer */
    $stmt->store_result();

    printf("Number of rows: %d.\n", $stmt->num_rows);

### &style.procedural;

    <?php

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $link = mysqli_connect("localhost", "my_user", "my_password", "world");

    $query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
    $stmt = mysqli_prepare($link, $query);
    mysqli_stmt_execute($stmt);

    /* store the result in an internal buffer */
    mysqli_stmt_store_result($stmt);

    printf("Number of rows: %d.\n", mysqli_stmt_num_rows($stmt));

&examples.outputs;

    Number of rows: 20.

&reftitle.seealso;

- `mysqli_prepare`
- `mysqli_stmt_result_metadata`
- `mysqli_stmt_fetch`