Copy CodeThe code is as follows:
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 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 \ '
'. $templine. '\': ' . Mysql_error (). '
');
Reset Temp variable to empty
$templine = ";
}
}
echo "Tables imported successfully";
?>http://www.bkjia.com/PHPjc/742450.html www.bkjia.com true http://www.bkjia.com/PHPjc/742450.html techarticle Copy the code as follows:? PHP//Name of the file $filename = ' churc.sql ';//MySQL host $mysql _host = ' localhost ';//MySQL Usernam E $mysql _username = ' root '; MySQL Password ...