php / php/php-src

Problem with mysqli_options and persistent connections in mysqli.

未关闭
#7,808 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Extension: mysqli Status: Verified
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 13 小时
30 天内合并 PR
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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

报告指出了 mysqli_init()、mysqli_options()、mysqli_real_connect() 以及持久化 p: 连接;首先,按照文档规定的选项顺序复现提供的 PHP 脚本。没有指定源文件或测试,因此请跟踪断开的池连接被替换时该选项的处理方式。当该选项仍然有效且第二个查询返回整数时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
mysql, php
领域
databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。