Skip to content

mysqli_change_user does not allow to use NULL for $database param #10382

Open
@kamil-tekiela

Description

@kamil-tekiela

Description

According to the documentation, the third parameter in mysqli_change_user is nullable (not optional though) and passing NULL should connect to the same database.

If desired, the null value may be passed resulting in only changing the user and not selecting a database. To select a database in this case use the mysqli_select_db() function.

But to my knowledge this was never possible and is still not supported by mysqli. This code will reset database to NULL

$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
$mysqli->change_user("my_user", "my_password", null);
var_dump($mysqli->query("SELECT DATABASE()")->fetch_row()[0]);

Resulted in this output:

NULL

But I expected this output instead:

string(4) "test"

PHP Version

All versions

Operating System

No response

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