gpt4 book ai didi

php - 将 LOAD DATA UNFILE MySQL UPDATE 转换为 php

转载 作者:行者123 更新时间:2023-11-30 22:40:28 25 4
gpt4 key购买 nike

我写了一个 MySQL 更新语句,它从一个 csv 文件更新一个表。当从 phpMyAdmin 运行时,此命令完美运行,但当尝试从 php 运行时,它失败了。它说我的语法有错误。

这是我的 php 代码片段

$file = "/root/location/to/file.csv";
$db = IEM::getDatabase();
$recover = "CREATE TEMPORARY TABLE temptable LIKE email_list_subscribers; LOAD DATA INFILE '$file' INTO TABLE temptable FIELDS TERMINATED BY ',' (emailaddress, subscriberid, confirmed); UPDATE email_list_subscribers INNER JOIN temptable on temptable.subscriberid = email_list_subscribers.subscriberid SET email_list_subscribers.confirmed = temptable.confirmed; DROP TEMPORARY TABLE temptable;";
$result = $db->Query($recover);

关于我哪里出错有什么建议吗?

错误消息被截断为:

You have an error in your SQL syntax; check the manual that correspond...

最佳答案

感谢@spencer7593 的建议。 Query 函数不支持多个查询。因此我的回答如下:

$file = "/root/location/to/file.csv";
$db = IEM::getDatabase();
$recover = "CREATE TEMPORARY TABLE temptable LIKE email_list_subscribers;";
$result = $db->Query($recover);
$recover ="LOAD DATA INFILE '$file' INTO TABLE temptable FIELDS TERMINATED BY ',' (emailaddress, subscriberid, confirmed);";
$result = $db->Query($recover);
$recover = "UPDATE email_list_subscribers INNER JOIN temptable on temptable.subscriberid = email_list_subscribers.subscriberid SET email_list_subscribers.confirmed = temptable.confirmed;";
$result = $db->Query($recover);
$recover = "DROP TEMPORARY TABLE temptable;";
$result = $db->Query($recover);

关于php - 将 LOAD DATA UNFILE MySQL UPDATE 转换为 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31249194/

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