Use a PHP statement to import a database *.sql file into a database _php tips

Source: Internet
Author: User
Tags explode
The simplest PHP statement imports the database *.sql file into the database
Copy Code code as follows:

$sql =file_get_contents ("Text.sql"); Read the SQL statement as a string into the $sql
$a =explode (";", $sql); Use the explode () function to put the $sql string ";" Split an array

foreach ($a as $b) {//traversal array
$c = $b. ";"; After the split is no ";" , because the SQL statement is ";" End, so before executing SQL, add it to the
mysql_query ($c); Execute SQL statement
}

In many setup programs, you will see the installation of the database, the other mysterious behind is such a simple few code. First, there will be a SQL file in the installation and then follow the code in PHP.

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.