Problem with mysqli_options and persistent connections in mysqli.
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 https://www.php.net/manual/en/mysqli.options.php
mysqli_options() should be called after mysqli_init() and before mysqli_real_connect().
But, when using persistent connections and the connection in the pool is broken,
when creating a new connection, the MYSQLI_OPT_INT_AND_FLOAT_NATIVE option is lost.
Setting the option AFTER calling real_connect solves the problem
The following code:
<?php
\mysqli_report(MYSQLI_REPORT_ERROR);
function connect(): mysqli {
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, 1);
$mysqli->real_connect('p:127.0.0.1', 'user', 'password');
return $mysqli;
}
$mysqli1 = connect();
var_dump($mysqli1->query("SELECT 1")->fetch_row()[0]); // int
@$mysqli1->query("KILL {$mysqli1->thread_id}");
unset($mysqli1);
$mysqli2 = connect();
var_dump($mysqli2->query("SELECT 2")->fetch_row()[0]); // string, but int is expected
// next ok
$mysqli2->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, 1);
var_dump($mysqli2->query("SELECT 3")->fetch_row()[0]); // int
Resulted in this output:
int(1)
string(1) "2"
int(3)
But I expected this output instead:
int(1)
int(2)
int(3)
PHP Version
PHP 8.0.14, 8.1.1
Operating System
Debian 9.13, Ubuntu 21.10
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
The report identifies mysqli_init(), mysqli_options(), mysqli_real_connect(), and persistent p: connections; start by reproducing the supplied PHP script with the documented option order. No source file or test is named, so trace how the option is handled when a broken pooled connection is replaced. Done means the option remains effective and the second query returns an integer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100