0

我正在尝试执行 DROP TEMPORARY TABLE 语句。我已经使用 MySQL Workbench 运行了该语句,它在那里工作。我已确保在 PHP 和 MySQL Workbench 中以同一用户身份成功登录。

我尝试使用 mysqli::query() 和 mysqli::prepare 然后 mysqli::execute() 方法。当我尝试执行 DROP TEMPORARY TABLE 语句时,两者都不起作用。但是,当我执行 INSERT 或 SELECT 语句时,两者都有效。

此代码不会返回错误,但也不会在数据库中执行:

public function executeSQL()
{       
    // SQL statement using query method
    if (!$this->mySQLi->query("DROP TEMPORARY TABLE IF EXISTS TIME_INTERVAL_DATA") ) 
    {
        $this->writeSQLErrorToLog("Query method returned an error.");
    }
    if(!$this->mySQLi->commit()) 
    {
        // Committing the transaction failed.
        $this->writeSQLErrorToLog("Commit method returned an error.");
    }

    // SQL statement using prepare and execute methods
    $stmt = $this->mySQLi->prepare("DROP TEMPORARY TABLE IF EXISTS TIME_INTERVAL_DATA");
    if($stmt) 
    {
        if(!$stmt->execute())
        {
            // Execute method returned an error.
            $this->writeSQLErrorToLog("Execute method returned an error.");
            $this->throwMySQLErrorAndCloseStatement($stmt);
        }
    } else {
        // Prepare method returned an error.
        $this->writeSQLErrorToLog("Prepare method returned an error.");
        return;
    }
    // ...
}

但是,以下代码确实在数据库中执行:

$stmt = $this->mySQLi->prepare("INSERT INTO TABLE1 (ID) VALUES (1)");
if(!$stmt->execute()) {
    // Return the MySQL Error message and number
    $this->throwMySQLErrorAndCloseStatement($stmt);
}

我一直在阅读尽可能多的 MySQL 和 PHP 文档。我已经阅读并重新阅读了有关上述所有 mysqli 方法的文档。我已经阅读并尝试了使用 mysqli::escape_string() 的变体,但是当我使用它时会返回错误。我还尝试了许多不同 SQL 语句的变体。

简而言之,所有 INSERT 和 SELECT 语句都有效。但是,DROP TEMPORARY TABLE 语句永远不会起作用,也永远不会返回错误。我真的在这个问题上摸不着头脑。任何帮助将非常感激!!

4

0 回答 0