Copy Code code as follows:
<?php
Name of the file
$filename = ' Churc.sql ';
MySQL Host
$mysql _host = ' localhost ';
MySQL username
$mysql _username = ' root ';
MySQL Password
$mysql _password = ';
Database Name
$mysql _database = ' dump ';
Connect to MySQL Server
Mysql_connect ($mysql _host, $mysql _username, $mysql _password) or Die (' Error connecting to MySQL server: '. Mysql_error ()) ;
Select Database
mysql_select_db ($mysql _database) or Die (' Error selecting MySQL database: '. mysql_error ());
Temporary variable, used to store current query
$templine = ';
Read in entire file
$lines = file ($filename);
Loop through each line
foreach ($lines as $line)
{
Skip it if it ' s a comment
if (substr ($line, 0, 2) = '--' | | | $line = = ')
Continue
Add this line to the current segment
$templine. = $line;
If it has a semicolon at the end, it's the end of the query
if (substr (Trim ($line),-1, 1) = = '; ')
{
Perform the query
mysql_query ($templine) or print (' Error performing query \ <strong> '. $templine. '\': ' . Mysql_error (). ' <br/><br/> ');
Reset Temp variable to empty
$templine = ';
}
}
echo "Tables imported successfully";
?>