PHP Import. sql file to MySQL database
PHP tutorial Import. sql file to MySQL Tutorial database tutorial
Set_time_limit (0); Setting the time-out to 0 indicates that it has been executed. When PHP is not valid in Safe mode, this may cause the import to time out, which requires a segmented import
$db = new MySQL ($location [' Host '], $location [' hostname '], $location [' Hostpass '], $location [' table '], ' UTF8 ', $location [' Ztime ']);
$fp = @fopen ($sql, "R") or Die ("Cannot open SQL file $sql");//Open File
while ($sql =getnextsql ()) {
mysql_query ($sql);
}
echo "User data import complete!";
Fclose ($fp) or Die ("can ' t close file $file _name");//Close files
Fetch SQL from File
function Getnextsql () {
Global $fp;
$sql = "";
while ($line = @fgets ($fp, 40960)) {
$line = Trim ($line);
The following three sentences are not required in the high version of PHP and may need to be modified in some lower versions
$line = str_replace ("\ \", "\", $line);
$line = Str_replace ("'", "'", $line);
$line = Str_replace ("\ r \ n", Chr. chr), $line);
$line = Stripcslashes ($line);
if (strlen ($line) >1) {
if ($line [0]== "-" && $line [1]== "-") {
Continue
}
}
$sql. = $line. chr (10);
if (strlen ($line) >0) {
if ($line [strlen ($line) -1]== ";") {
Break
}
}
}
return $sql;
}
?>
http://www.bkjia.com/PHPjc/630813.html www.bkjia.com true http://www.bkjia.com/PHPjc/630813.html techarticle PHP Import. sql file to MySQL database PHP tutorial import. sql file to MySQL Tutorial database tutorial set_time_limit (0);//Set time-out to 0, indicating that it has been executed. When PHP is in Safe mode ...