mysqli_change_user does not allow to use NULL for $database param
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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