PDO execute not correctly binding booleans
还没有人认领这个 Issue。
评估
调研方向
使用报告的 PHP 版本重现 PDO 示例,然后阅读 ext/pdo/pdo_stmt.c 中第 411-425 行附近的代码,并将其与第 1465-1475 行附近的 bindValue() 进行比较。确认 execute() 如何处理布尔值,并添加回归测试覆盖以展示预期的 BIT 绑定行为。
由索引模型根据 Issue 内容生成。
描述
Description
The following code:
<?php
$db = new PDO(...);
$sql = <<<SQL
CREATE TABLE test (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`birthday` DATE NOT NULL,
`name` VARCHAR(40) NOT NULL,
`salary` INT NOT NULL,
`boss` BIT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
SQL;
$query = $db->prepare($sql);
$query->execute();
$sql = <<<SQL
INSERT INTO test
(birthday, name, salary, boss)
VALUES (:birthday, :name, :salary, :boss)
SQL;
$query = $db->prepare($sql);
$staff = [
[
'birthday' => (new DateTime('1995-05-01'))->format('Y-m-d'),
'name' => 'Sharon',
'salary' => '200',
'boss' => TRUE,
],
];
foreach ($staff as $member) {
/* works
$query->bindValue('birthday', $member['birthday'], PDO::PARAM_STR);
$query->bindValue('name', $member['name'], PDO::PARAM_STR);
$query->bindValue('salary', $member['salary'], PDO::PARAM_INT);
$query->bindValue('boss', $member['boss'], PDO::PARAM_BOOL);
$query->execute();
*/
// does not work
$query->execute($member);
}
Resulted in this output:
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'boss' at row 1
But I expected execute() not to throw an error.
I clearly see the problem in the source as the parameter is always set to be a string on line 424:
Can't the execute() code be improved to check for the param type like it is done in bindValue()?
PHP Version
8.2.0 RC3
Operating System
Alpine Linux
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 103
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
php/php-src 的其他 Issue
-
Bug SAPI: cli_server Status: Verified
难度 2/5 1-3 小时 新手友好度 88/100
-
Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 76/100
-
Bug Status: Needs Triage
难度 1/5 1 小时以内 新手友好度 90/100
-
Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 78/100
-
Bug Category: Tests Status: Verified
难度 2/5 1-3 小时 新手友好度 68/100
相似的 Issue
-
[adam] AdamNet network read doesn't cap to MAX_ADAM_PACKET_LEN, overflows client receive buffers 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
FujiNetWIFI/fujinet-firmware#1649 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
HarbourMasters/Shipwright#7229 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
riscv-software-src/riscv-isa-sim#2435 · 1 条评论 ·
-
bug Self Built Image SNAPSHOT Supported Device target/ramips
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 76/100