【发布时间】:2016-01-01 04:07:09
【问题描述】:
问题:即使我的$settings 数组中有值 (int),MySQL 也会在值为 0 和 2 时将NULL 写入表中。
作为参考,$settings 数组中的每个索引都是[0] = max 和[1] = min 的数组。
public function updateAdaptiveArmour($gameid, $shipid, $settings){
foreach ($settings as $key => $value){
debug::log($key." ".$value[0]." ".$value[1]);
//just to show the contents
// [561103190304f][2015-10-04 12:44:41] particle 4 2
// [56110319035b3][2015-10-04 12:44:41] laser 0 0
// [56110319035b3][2015-10-04 12:44:41] molecular 0 0
}
try {
if ($stmt = $this->connection->prepare(
"UPDATE
tac_adaptivearmour
SET
particlealloc = ?,
laseralloc = ?,
molecularalloc = ?
WHERE
gameid = ?
AND shipid = ?
"
))
{
$stmt->bind_param('iiiii', $settings[0][1], $settings[1][1], $settings[2][1], $gameid, $shipid);
$stmt->execute();
$stmt->close();
}
}
catch(Exception $e) {
throw $e;
}
}
理想情况下,对于此示例,我希望更新为 2 / 0 / 0 而不是 null / null / null。
【问题讨论】:
-
mysqli不会抛出异常,除非您使用过:Turning query errors to Exceptions in MySQLi。where之前有一个额外逗号的语法错误 -
修正了错字,当我缩短代码以在此处显示时的剩余部分(最初,数组有更多条目)。所以这不是原因。我启用了调试并得到 mysql 错误。我说它正在更新表,但使用 NULL。