Skip to content

mysqli::options does not respect error reporting configuration #20968

@morozov

Description

@morozov

Description

The following code:

<?php

$mysqli = new mysqli();
$value = $mysqli->options(-1, 'invalid_option');
var_dump($value);

Resulted in this output:

bool(false)

But I expected this output instead:

mysqli_sql_exception

Per the mysqli::options documentation,

If mysqli error reporting is enabled (MYSQLI_REPORT_ERROR) and the requested operation fails, a warning is generated. If, in addition, the mode is set to MYSQLI_REPORT_STRICT, a mysqli_sql_exception is thrown instead.

Per the mysqli_driver::$report_mode documentation, this should be the default behavior:

PHP 8.1. The default value is now MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT. Previously, it was MYSQLI_REPORT_OFF.

For reference, mysqli::set_charset behaves as expected:

<?php

$mysqli = new mysqli('127.0.0.1', 'root', 'Passw0rd!');
try {
    $mysqli->set_charset('garbage');
} catch (mysqli_sql_exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
// Caught exception: Invalid character set was provided

PHP Version

PHP 8.5.2 (cli) (built: Jan 13 2026 21:40:53) (NTS)
Copyright (c) The PHP Group
Built by Shivam Mathur
Zend Engine v4.5.2, Copyright (c) Zend Technologies
    with Xdebug v3.5.0, Copyright (c) 2002-2025, by Derick Rethans
    with Zend OPcache v8.5.2, Copyright (c), by Zend Technologies

Operating System

macOS

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions