I saw similar problems when using multi_query
with queries that can create or modify tables. In particular, I tend to get InnoDB 1005 errors that seem to be related to foreign keys; it, like MySQL, does not completely complete one statement before moving on to the next, so foreign keys do not have a corresponding referent.
On one system, I break up problematic statements into my own files. In another case, I actually ran each command separately, breaking semicolons:
function load_sql_file($basename, $db) { // Todo: Trim comments from the end of a line log_upgrade("Attempting to run the `$basename` upgrade."); $filename = dirname(__FILE__)."/sql/$basename.sql"; if (!file_exists($filename)) { log_upgrade("Upgrade file `$filename` does not exist."); return false; } $file_content = file($filename); $query = ''; foreach ($file_content as $sql_line) { $tsl = trim($sql_line); if ($sql_line and (substr($tsl, 0, 2) != '--') and (substr($tsl, 0, 1) != '#')) { $query .= $sql_line; if (substr($tsl, -1) == ';') { set_time_limit(300); $sql = trim($query, "\0.. ;"); $result = $db->execute($sql); if (!$result) { log_upgrade("Failure in `$basename` upgrade:\n$sql"); if ($error = $db->lastError()) { log_upgrade("$error"); } return false; } $query = ''; } } } $remainder = trim($query); if ($remainder) { log_upgrade("Trailing text in `$basename` upgrade:\n$remainder"); if (DEBUG) trigger_error('Trailing text in upgrade script: '.$remainder, E_USER_WARNING); return false; } log_upgrade("`$basename` upgrade successful."); return true; }
source share