Problem with mysqli_options and persistent connections in mysqli.
まだ誰も着手していません。
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.1k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
このレポートでは、mysqli_init()、mysqli_options()、mysqli_real_connect()、および永続的な p: 接続が特定されています。まず、文書化されているオプションの順序で、提供された PHP スクリプトを再現してください。ソースファイルもテストも指定されていないため、壊れたプール接続が置き換えられる際にオプションがどのように処理されるかを追跡してください。オプションの有効性が維持され、2 回目のクエリが整数を返せば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- mysql, php
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100