我正在使用以下代码更新现有数据库。
ALTER IGNORE TABLE `payouts` ENGINE = InnoDB;
ALTER IGNORE TABLE `users_UNIQUE` ENGINE = InnoDB;
DROP INDEX IF EXISTS `userhash` ON `payouts`;
DROP INDEX IF EXISTS `address` ON `payouts`;
DROP INDEX IF EXISTS `ip` ON `payouts`;
DROP INDEX IF EXISTS `slid` ON `payouts`;
ALTER TABLE `payouts` ADD KEY `userhash` (`userhash`),ADD KEY `address` (`address`),ADD KEY `ip` (`ip`),ADD KEY `slid` (`slid`);
DROP INDEX IF EXISTS `userhash` ON `users_UNIQUE`;
DROP INDEX IF EXISTS `address` ON `users_UNIQUE`;
ALTER TABLE `users_UNIQUE` ADD KEY `userhash` (`userhash`),ADD KEY `address` (`address`);
UPDATE `settings_UNIQUE` SET `value` = '58.3' WHERE `settings_UNIQUE`.`name` = 'version';
问题在于更新到当前版本的最后一个查询不会更新。 我没有收到任何错误消息,只是没有更新。
如果我直接通过SQL在数据库中运行它,它将更新而不是通过PHP。
我正在使用PHP。
$db_update = array(
'58.3' => array(
"ALTER IGNORE TABLE `payouts` ENGINE = InnoDB;",
"ALTER IGNORE TABLE `users_".$faucet_id."` ENGINE = InnoDB;",
"DROP INDEX IF EXISTS `userhash` ON `payouts`;",
"DROP INDEX IF EXISTS `address` ON `payouts`;",
"DROP INDEX IF EXISTS `ip` ON `payouts`;",
"DROP INDEX IF EXISTS `slid` ON `payouts`;",
"ALTER TABLE `payouts` ADD KEY `userhash` (`userhash`),ADD KEY `address` (`address`),ADD KEY `ip` (`ip`),ADD KEY `slid` (`slid`);",
"DROP INDEX IF EXISTS `userhash` ON `users_".$faucet_id."`;",
"DROP INDEX IF EXISTS `address` ON `users_".$faucet_id."`;",
"ALTER TABLE `users_".$faucet_id."` ADD KEY `userhash` (`userhash`),ADD KEY `address` (`address`);",
"UPDATE `settings_".$faucet_id."` SET `value` = '58.3' WHERE `settings_".$faucet_id."`.`name` = 'version';"
)
);
foreach($db_update as $v => $update){
if ($v <= $installed) continue;
foreach($update as $query){
if(!$conn->query($query)){
echo $conn->error;
exit;
}
}
}
答案 0 :(得分:0)
为解决此问题,我在查询循环后添加了更新。
if($installed && $version > $installed){
$conn->query("UPDATE `settings_".$faucet_id."` SET `value` = '".$version."' WHERE `settings_".$faucet_id."`.`name` = 'version'");
}