PDO更新查询运行更改没有行。没有错误

时间:2015-09-30 06:36:16

标签: php mysql pdo

所以我正在运行PDO更新工作,并且由于某种原因它不会更新表...

$business_id = 9874128;
$hidden = 1;
$query = "UPDATE business_property_overrides SET hidden=? WHERE business_id=?";

try {
      $stmt = $pdo->prepare($query);
      $stmt->execute(array($business_id, $hidden));
}

由于某些原因,即使我没有错误,也不会更新。现有的表架构如下所示,数据为:

现有数据集的business_id = 9874128,隐藏设置为0,但在运行上述代码时不会更新。

CREATE TABLE `business_property_overrides` (
  `business_id` int(11) NOT NULL,
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(512) NOT NULL,
  `apt_type` varchar(25) DEFAULT NULL,
  `apt_num` varchar(9) DEFAULT NULL,
  `street_address` varchar(255) DEFAULT NULL,
  `city` varchar(255) DEFAULT NULL,
  `state` varchar(255) DEFAULT NULL,
  `zip` varchar(25) DEFAULT NULL,
  `phone` varchar(11) DEFAULT NULL,
  `url` varchar(512) DEFAULT NULL,
  `hours` varchar(100) DEFAULT NULL,
  `openhours` varchar(100) DEFAULT NULL,
  `location` point DEFAULT NULL,
  `yelp` varchar(512) DEFAULT '0',
  `twitter` varchar(512) DEFAULT '0',
  `hidden` tinyint(1) DEFAULT '0',
  `merged` int(11) DEFAULT NULL,
  `closed` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `business_id` (`business_id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9874134 DEFAULT CHARSET=utf8;

2 个答案:

答案 0 :(得分:0)

hiddenTINYINT 1 characters long,您正在为business_id分配7 characters long,这是错误。

更改

$stmt->execute(array($business_id, $hidden));

要:

$stmt->execute(array($hidden,$business_id))

答案 1 :(得分:0)

由于我已经对here发表了评论,或者你可以简单地使用占位符而不关心发生的情况,如

$query = "UPDATE business_property_overrides SET hidden = :hidden WHERE business_id = :business_id";

try {
      $stmt = $pdo->prepare($query);
      $stmt->execute(array(":business_id" => $business_id, ":hidden" => $hidden));
}