除非我误解了你,否则 AutoExecute 似乎不适合这项工作。如果您需要对表中的所有记录进行一次性转换,我只需重命名这些列。
ALTER TABLE `users`
CHANGE COLUMN `lastname` `firstname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `id`,
CHANGE COLUMN `firstname` `lastname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `firstname`;
或者在 PHP/ADODB 中:
$sql = "ALTER TABLE `users`
CHANGE COLUMN `lastname` `firstname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `id`,
CHANGE COLUMN `firstname` `lastname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `firstname`;";
if (($result = $conn->Execute($sql)) === false)
exit($sql.'<br />'.$conn->errorMsg());
如果您需要针对特定记录,您可以使用临时变量。
$sql = "UPDATE users
SET firstname=(@temp:=firstname), firstname = lastname, lastname = @temp
WHERE id=2";
if (($result = $conn->Execute($sql)) === false)
exit($sql.'<br />'.$conn->errorMsg());
干杯