Importing a database *.sql file into a database using a PHP statement _php tutorial

Source: Internet
Author: User
The simplest PHP statement to import a database *.sql file into the database
Copy CodeThe code is as follows:
$sql =file_get_contents ("Text.sql"); Reads SQL statements into $sql as strings
$a =explode (";", $sql); Use the explode () function to put the $sql string ";" Split into arrays

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

In many installers you will see the installation of the database, the other mysterious behind is such a simple few lines of code. First, the installation will have a SQL file, and then follow the above code in PHP execution.

http://www.bkjia.com/PHPjc/765158.html www.bkjia.com true http://www.bkjia.com/PHPjc/765158.html techarticle The simplest PHP statement to import the database *.sql file into the database copy code code is as follows: $sql =file_get_contents ("Text.sql");//Read the SQL statement as a string into the $sql $a =explode (";" $sql );...

  • 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.