PHP mysqli_refresh() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_refresh() asks the MySQL server to flush caches or refresh certain server state, using MYSQLI_REFRESH_* flags.

It is rarely needed in application code. As of PHP 8.4 it is deprecated; use FLUSH SQL statements instead. Keep this page honest: most tutorials never call refresh().

Syntax

Call mysqli_refresh() with the values you need. Start with this line.

PHP
$ok = mysqli_refresh($mysql, MYSQLI_REFRESH_TABLES);
CallWhat it does
mysqli_refresh($link, MYSQLI_REFRESH_GRANT)Asks the server to reload grant tables when the flag is supported.
$mysqli->refresh(MYSQLI_REFRESH_TABLES)Object-oriented form with a refresh flag constant.
mysqli_refresh($link, MYSQLI_REFRESH_STATUS)Requests a status refresh; returns true or false.

Deprecated in PHP 8.4. Prefer running an explicit FLUSH ... query when you truly need a flush. Flags come from the MySQLi MYSQLI_REFRESH_* constants. Ordinary CRUD apps almost never need this.

Library declarations
PHP
mysqli_refresh(mysqli $mysql, int $flags): bool

Parameters

ParameterDescription
mysqlRequired. Procedural style only: a mysqli connection.
flagsRequired. One or more MYSQLI_REFRESH_* values that select what to refresh.

Return Value

Return ValueDescription
trueThe refresh request succeeded.
falseThe refresh request failed.

PHP Examples

Example 1 — Show the Call Shape

Illustrate the procedural call and a fixed success message without a live server.

PHP
<?php
$flag = defined('MYSQLI_REFRESH_TABLES') ? 'MYSQLI_REFRESH_TABLES' : 'tables-flag';
$demoOk = true; // stand-in for mysqli_refresh($link, MYSQLI_REFRESH_TABLES)

echo 'flag: ', $flag, PHP_EOL;
echo $demoOk ? 'refresh ok' : 'refresh failed', PHP_EOL;

How It Works

  1. Real code passes a mysqli link and a MYSQLI_REFRESH_* constant.
  2. This demo only prints the idea of a successful refresh.
  3. Sample output when connected to a demo database would be a boolean success from the server.
  4. On PHP 8. 4+ expect deprecation notices if you still call it.

Example 2 — Prefer FLUSH Instead

Show the modern teaching alternative as a SQL string, not a live query.

PHP
<?php
$sql = 'FLUSH TABLES';
echo 'prefer SQL: ', $sql, PHP_EOL;
echo 'mysqli_refresh() is deprecated in PHP 8.4', PHP_EOL;

How It Works

  1. FLUSH TABLES is the clear SQL form of a common refresh intent.
  2. Run FLUSH through prepare/query only when your role is allowed to flush.
  3. mysqli_refresh() wrapped the same idea behind C API flags.
  4. New projects should avoid the deprecated function.

Example 3 — OO Method Name

Object style uses the same flags and returns a boolean.

PHP
<?php
class DemoMysqli {
    public function refresh($flags) {
        return is_int($flags);
    }
}

$mysqli = new DemoMysqli();
echo $mysqli->refresh(256) ? 'true' : 'false', PHP_EOL;

How It Works

  1. OO code calls $mysqli->refresh($flags).
  2. Procedural code passes the link first.
  3. The demo only checks that a flag integer was provided.
  4. Real MySQL may still refuse the flush based on privileges.

Frequently Asked Questions

It asks MySQL to refresh selected caches or server state using MYSQLI_REFRESH_* flags.
No. It is rarely used and is deprecated as of PHP 8.4. Prefer FLUSH SQL statements.
Mostly in admin or legacy tooling. Normal web apps almost never need it.
They select which refresh actions to request, such as tables or grants, matching MySQL refresh options.
true on success and false on failure.

Next: mysqli_release_savepoint()

mysqli_release_savepoint() removes a named savepoint from the current transaction without .

mysqli_release_savepoint() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful