PHP Import. sql file to MySQL database _php tutorial

Source: Internet
Author: User
Tags chr mysql tutorial set time
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.