PDO无效的布尔参数[重复]

问题描述 投票:0回答:1

我正在尝试使用以下方法更新表:

$stmt = $db->prepare("
    UPDATE Business SET
        Business.Name = ?,
        Business.Phone = ?,
        Business.Fax = ?,
        Business.Address = ?,
        Business.City = ?,
        Business.StateId = ?,
        Business.Zip = ?,
        Business.Referral = ?,
        Business.IsRemindedWeekly = ?,
        Business.DeletedOn = ?
    WHERE
        Business.BusinessId = ?");

// Execute the query
$stmt->execute(array(
    $_POST["Name"],
    $_POST["Phone"],
    $_POST["Fax"],
    $_POST["Address"],
    $_POST["City"],
    $_POST["StateId"],
    $_POST["Zip"],
    $_POST["Referral"],
    $_POST["IsRemindedWeekly"],
    ($_POST["DeletedOn"] && $_POST["DeletedOn"] != "0000-00-00" ? $_POST["DeletedOn"] : null),
    $_POST["BusinessId"]
));

我的模式如下:

CREATE TABLE `business` (
  `BusinessId` int(11) NOT NULL,
  `Name` varchar(255) NOT NULL,
  `Phone` char(10) DEFAULT NULL,
  `Fax` char(10) DEFAULT NULL,
  `Address` varchar(255) DEFAULT NULL,
  `City` varchar(64) DEFAULT NULL,
  `StateId` int(11) DEFAULT NULL,
  `Zip` char(5) DEFAULT NULL,
  `Signature` blob DEFAULT NULL,
  `Referral` varchar(255) DEFAULT NULL,
  `IsRemindedWeekly` bit(1) NOT NULL DEFAULT b'0',
  `DeletedOn` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

但是,无论发送到请求的值如何,IsRemindedWeekly列始终设置为1。检查网络选项卡时,有效负载似乎正在发送字符串值“ 1”,但是即使我将参数化值更改为:

($_POST["IsRemindedWeekly"] == "1" ? 1 : 0)

(请注意非类型比较运算符),但是无论如何,更新操作后,数据库中的值仍为1。我想念什么吗?

php mysql pdo
1个回答
0
投票

[期望为PDO::PARAM_BOOL时,您可能应该为其提供boolean

© www.soinside.com 2019 - 2024. All rights reserved.