我会用它打开它gzfile
,在查询分隔符上将它分开,然后放入 mysqli::query
$file = implode('', gzfile($sqlFile)); // there doesn't exist a gz* function which reads it completely into a string?
$query = $substring_delimiter = "";
$last_was_backslash = false;
$outside_begin_end = true;
$delimiter = ';';
for ($i = 0; $i < strlen($file); $i++) {
if ($i > 3 && !strcasecmp(substr($file, $i - 4, 5), "BEGIN") && !$substring_delimiter)
$outside_begin_end = false;
if (!$outside_begin_end && !strcasecmp(substr($file, $i - 2, 3), "END") && !$substring_delimiter)
$outside_begin_end = true;
if ($i > 7 && !strcasecmp(substr($file, $i - 8, 9), "DELIMITER") && trim($query) == '') {
$delimiter = '';
do {
$delimiter .= $file[$i];
} while (++$i < strlen($file) && $file[$i] != PHP_EOL)
$delimiter = trim($delimiter);
}
if ($file[$i] == '\'' || $file[$i] == '"')
if ($substring_delimiter) {
if ($substring_delimiter == $file[$i] && !$last_was_backslash)
$substring_delimiter = "";
} else {
$substring_delimiter = $file[$i];
}
if ($outside_begin_end && !$substring_delimiter && !strcasecmp($delimiter, substr($file, $i))) {
$sql->query($query); // where $sql is a mysqli instance
$query = "";
} else {
$query .= $file[$i];
}
if ($file[$i] == '\\')
$last_was_backslash = !$last_was_backslash;
else
$last_was_backslash = false;
}
if (trim($query) != "")
$sql->query($query);