gpt4 book ai didi

php - PDO bindValue with\PDO::PARAM_BOOL 导致语句执行失败

转载 作者:可可西里 更新时间:2023-11-01 06:32:20 24 4
gpt4 key购买 nike

在一台服务器设置中,我遇到了非常奇怪的错误。有 PHP 5.3.6 和 PDO Driver for MySQL,客户端库版本 5.1.61。一切都是手工编译的。

当我将 params 与 bindValue 绑定(bind)并将第三个参数设置为\PDO::PARAM_BOOL 时,语句执行返回 false 并且没有任何反应(没有数据插入 MySQL,甚至根本没有异常)。当我不使用第三个参数时,一切顺利。事实上我不能省略第三个参数,因为 Doctrine2 DBAL 在转换参数时设置它...

代码如下:

<?php
$pdo = new \PDO('mysql:host=***;dbname=***', '***', '***'); // hidden DB access
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare('insert into outage (name, description, start_at, end_at, is_exception, extranet_id) values (?,?,?,?,?,?)');
$stmt->bindValue(1, 'Test name', \PDO::PARAM_STR);
$stmt->bindValue(2, 'Test desc', \PDO::PARAM_STR);
$stmt->bindValue(3, '2012-01-01 00:00:00', \PDO::PARAM_STR);
$stmt->bindValue(4, null, \PDO::PARAM_NULL);
$stmt->bindValue(5, false, \PDO::PARAM_BOOL);
$stmt->bindValue(6, 2, \PDO::PARAM_INT);
var_dump(array('stmt result' => ($result = $stmt->execute()), 'last insert id' => $pdo->lastInsertId(), 'stmt err code' => $stmt->errorCode(), 'pdo err code' => $pdo->errorCode()));

结果:

array(4) {
["stmt result"]=>
bool(false)
["last insert id"]=>
string(1) "0"
["stmt err code"]=>
string(5) "00000"
["pdo err code"]=>
string(5) "00000"
}

可能会出什么问题?我已经在其他 4 台服务器上试过了,但没有遇到这个错误。此外,如果我将“0”(作为字符串)传递给 $stmt->bindValue(5, false,\PDO::PARAM_BOOL);,效果很好。

最佳答案

我在使用 PHP 5.3.10 的 Ubuntu 上遇到了同样的问题。 (有趣的是在 wamp 的 windows 上没有问题...)

实际上这是 pdo 中的一个已知错误:https://bugs.php.net/bug.php?id=38546

我使用 PDO::PARAM_INT 而不是 PDO::PARAM_BOOL。它运行良好,您不必像上面那样将 bool 值转换为字符串。

关于php - PDO bindValue with\PDO::PARAM_BOOL 导致语句执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10242312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com