【发布时间】:2014-11-07 05:21:01
【问题描述】:
我已经在 phpmyadmin 中测试了这个查询,它返回的正是我要查找的内容...它重复了 row1 并将标题更新为 DUPLICATE。
$sql = "CREATE TEMPORARY TABLE tmp
SELECT `unit_id`,
`title`,
`status_id`,
`category_id`,
`tags`,
`access_id`
FROM unit_genData
WHERE `unit_id`='1';
ALTER TABLE tmp
DROP COLUMN `unit_id`;
UPDATE tmp
SET `title` = 'DUPLICATE';
INSERT INTO unit_genData
SELECT 0,tmp.*
FROM tmp;
DROP TABLE tmp;";
然后我去把它添加到一个php页面,然后……
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ALTER TABLE tmp DROP COLUMNunit_id; UPDATE tmp ' at line 10
为什么会出现这个错误?
【问题讨论】:
-
post php code too..你如何执行查询?
-
您是否尝试用单引号将表名 tmp 括起来?
-
您是否将其称为
stored procedure? -
除非您使用
mysqli_multi_query(),否则您的查询将失败,因为您的查询必须是 1 个查询,所以它在您的第一个;上失败 -
为什么要创建一个表,然后用下一个查询改变它?为什么不按照您想要的方式创建它?
标签: php mysql alter-table