// Name of the file$filename = 'churc.sql';// MySQL host$mysql_host = 'localhost';// MySQL username$mysql_username = 'root';// MySQL password$mysql_password = '';// Database n " /> 亚洲精品国精品久久99热,麻豆成人在线播放,国产经典三级在线

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP處理SQL腳本文件導入到MySQL的代碼實例

復制代碼 代碼如下:<?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";
?>

php技術PHP處理SQL腳本文件導入到MySQL的代碼實例,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 岳阳市| 兴安盟| 海丰县| 衡东县| 长汀县| 宜春市| 丽水市| 上林县| 睢宁县| 左云县| 库车县| 会泽县| 祁阳县| 左云县| 昌乐县| 辽源市| 清丰县| 广汉市| 个旧市| 湟中县| 方正县| 怀宁县| 高邮市| 连城县| 额尔古纳市| 定西市| 孝昌县| 逊克县| 乌鲁木齐市| 蛟河市| 鱼台县| 长葛市| 深泽县| 英山县| 遵义县| 罗甸县| 五台县| 佳木斯市| 来凤县| 江门市| 花垣县|