gpt4 book ai didi

php - 错误SQL用php创建临时表

转载 作者:太空宇宙 更新时间:2023-11-03 11:29:02 25 4
gpt4 key购买 nike

我尝试从一个表中选择多个值,playlist_generate,有一个条件,创建一个临时表,更新一个字段然后插入我的表

$data_tabella_duplicata = $_POST['data_duplicata'];
$data_iniziale_originale = $_GET['data_iniziale'];

$query_duplica_playlist = "
DROP TABLE IF EXISTS temp_table;
CREATE TEMPORARY TABLE temp_table LIKE playlist_generate;
SELECT data_playlist, giorno_playlist, orario_playlist, nome_evento,nome_programma FROM playlist_generate WHERE data_playlist = '".$data_iniziale_originale."';
UPDATE temp_table SET data_playlist='".$data_tabella_duplicata."';
INSERT INTO playlist_generate SELECT null,data_playlist, giorno_playlist,orario_playlist, nome_evento, nome_programma FROM temp_table;
DROP TABLE temp_table;
";

$esegui_query_duplica_playlist = $connessione->query($query_duplica_playlist);
if ($connessione->error) {
try {
throw new Exception("MySQL error $connessione->error <br> Query:<br> $query_duplica_playlist", $connessione->errno);
} catch (Exception $e) {
echo "Error No: ".$e->getCode()." - ".$e->getMessage()."<br >";
echo nl2br($e->getTraceAsString());
}
}

但是我有一个错误我不明白

Error No: 1064 - MySQL error 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 'CREATE TEMPORARY TABLE temp_table LIKE playlist_generate; SELECT data_playlist, ' at line 2

我在 phpmyadmin 中尝试了代码,它有效

如果我用这个

$query_duplica_playlist = "
DROP TABLE IF EXISTS temp_table;
CREATE TEMPORARY TABLE temp_table ENGINE = MEMORY;
SELECT data_playlist, giorno_playlist, orario_playlist, nome_evento,nome_programma FROM playlist_generate WHERE data_playlist = '".$data_iniziale_originale."';
UPDATE temp_table SET data_playlist='".$data_tabella_duplicata."';
INSERT INTO playlist_generate SELECT null,data_playlist, giorno_playlist,orario_playlist, nome_evento, nome_programma FROM temp_table;
DROP TABLE temp_table;
";

$esegui_query_duplica_playlist = $connessione->multi_query($query_duplica_playlist);

我没有结果

最佳答案

来自docs -

You cannot use CREATE TEMPORY TABLE ... LIKE to create an empty table based on the definition of a table that resides in the mysql tablespace, InnoDB system tablespace (innodb_system), or a general tablespace. The tablespace definition for such a table includes a TABLESPACE attribute that defines the tablespace where the table resides, and the aforementioned tablespaces do not support temporary tables.

此外,您似乎试图同时运行多个查询。如果您使用的是 MySQLi,则需要使用 multi_query() .使用 multi_query(),尤其是在这种情况下并不理想,所以如果您发现自己想要使用此函数,请仔细考虑您的逻辑。

关于php - 错误SQL用php创建临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51517688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com