我有以下查询,用于复制表中的一行并更改一些列。
CREATE TEMPORARY TABLE temp_table AS
SELECT *
FROM table1
WHERE offertecode = '1c12a23453453458e492230df420972';
UPDATE temp_table
SET offertecode = '82a24c7da2342423424351804ab043',
id = NULL,
reference = '[COPY] subject';
INSERT INTO table1
SELECT *
FROM temp_table;
DROP TEMPORARY TABLE temp_table;这在phpmyadmin中工作得很好,但是我不能在PHP中让它工作,我得到一个错误:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax
to use near 'UPDATE temp_table SET offertecode = '82a24c7da2342423424351804ab043',
id = ' at line 5有人能帮助我如何在PHP中执行这个查询吗?
PHP代码:
$mysqli->query("CREATE TEMPORARY TABLE temp_table AS
SELECT *
FROM table1
WHERE offertecode = '1c12a23453453458e492230df420972';
UPDATE temp_table
SET offertecode = '82a24c7da2342423424351804ab043',
id = NULL,
reference = '[COPY] subject';
INSERT INTO table1
SELECT *
FROM temp_table;
DROP TEMPORARY TABLE temp_table;");谢谢!
发布于 2014-02-17 20:55:40
这并没有解决mysqli问题(在一个查询中有四个语句)。您应该单独运行这些程序。但是,您不需要四个语句。只需这样做:
insert into table1(offertecode, id, reference, <rest of columns>)
select '82a24c7da2342423424351804ab043' as offertecode, NULL as id, '[COPY] subject' as reference,
<rest of columns>
from table1
where offertecode = '1c12a23453453458e492230df420972';一条insert . . . select语句可以在两个部分中引用相同的表。即使是在MySQL中。
发布于 2015-05-04 06:19:03
您需要使用$mysqli->multi_query。基本答案是不能使用$mysqli->query运行多个查询。语法错误是由于第二个查询试图在$mysqli->query下运行,该查询只允许一个主查询。该查询可以包含子查询或嵌套查询,但只能包含一个主查询。要运行多个查询,必须使用$mysqli->multi_query
https://stackoverflow.com/questions/21828961
复制相似问题