Php import. SQL file to mysql database _ PHP Tutorial

Source: Internet
Author: User
Tags mysql tutorial
Php imports the. SQL file to the mysql database. Php import. SQL file to mysql database php Tutorial import. SQL file to mysql tutorial database tutorial set_time_limit (0); set the timeout time to 0, indicating that the operation is always executed. When php imports the. SQL file to the mysql database in safemode php

Php Tutorial import. SQL file to mysql tutorial database tutorial

Set_time_limit (0); // Set the timeout value to 0, indicating that the operation is always executed. If php is invalid in safe mode, the import may Time Out. in this case, you need to import data in multiple parts.
$ Db = new mysql ($ location ['host'], $ location ['hostname'], $ location ['hostpass'], $ location ['table'], "utf8", $ location ['ztime']);
$ Fp = @ fopen ($ SQL, "r") or die ("You cannot open an SQL file $ SQL"); // open a file
While ($ SQL = getnextsql ()){
Mysql_query ($ SQL );
}
// Echo "user data import completed! ";
Fclose ($ fp) or die ("can't close file $ file_name"); // close the file

// Obtain the SQL statement from the file one by one
Function getnextsql (){
Global $ fp;
$ SQL = "";
While ($ line = @ fgets ($ fp, 40960 )){
$ Line = trim ($ line );
// The following three statements are not required in the php version. you may need to modify them in some earlier versions.
// $ Line = str_replace ("\", "\", $ line );
// $ Line = str_replace ("'", "'", $ line );
// $ Line = str_replace ("\ r \ n", chr (13). chr (10), $ line );
// $ Line = stripcslashes ($ line );
If (strlen ($ line)> 1 ){
If ($ line [0] = "-" & $ line [1] = "-"){
Continue;
}
}
$ SQL. = $ line. chr (13). chr (10 );
If (strlen ($ line)> 0 ){
If ($ line [strlen ($ line)-1] = ";"){
Break;
}
}
}
Return $ SQL;
}
?>

Http://www.bkjia.com/PHPjc/630813.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630813.htmlTechArticlephp import. SQL file to mysql database php Tutorial import. SQL file to mysql tutorial database tutorial set_time_limit (0); // Set the time-out time to 0, indicating that the execution has been ongoing. When php is in safe mode...

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.