php / php/php-src

mysqli_change_user does not allow to use NULL for $database param

Open
#10,382 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: mysqli Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the mysqli_change_user entry point and compare the documented NULL behavior with the supplied PHP reproduction. Done means passing NULL preserves the existing database selection, with the reproduction confirming that SELECT DATABASE() still returns "test".

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.