最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP處理SQL腳本文件導(dǎo)入到MySQL的代碼實(shí)例

 更新時(shí)間:2014年03月17日 13:50:12   作者:  
通常在制作安裝程式,數(shù)據(jù)備份程序的時(shí)候會(huì)要用到這樣的代碼,我看網(wǎng)上有是有不太多,而且有些也不是很好用,有時(shí)候這種代碼直接用現(xiàn)成的可以節(jié)省很多時(shí)間,那么我就從stackoverflow轉(zhuǎn)了一個(gè)過來,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<?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 \'&lt;strong&gt;' . $templine . '\': ' . mysql_error() . '&lt;br /&gt;&lt;br /&gt;');
    // Reset temp variable to empty
    $templine = '';
}
}
 echo "Tables imported successfully";
?>

相關(guān)文章

最新評(píng)論

靖州| 乾安县| 兴宁市| 英德市| 清水河县| 鹤峰县| 鸡东县| 大港区| 奈曼旗| 柘城县| 越西县| 河南省| 衡阳市| 湘潭县| 珲春市| 昂仁县| 平和县| 裕民县| 上蔡县| 读书| 峨眉山市| 开化县| 平罗县| 长垣县| 揭东县| 曲周县| 防城港市| 南充市| 准格尔旗| 自治县| 怀来县| 汉川市| 南开区| 上饶市| 丘北县| 娄烦县| 潜山县| 松潘县| 沿河| 兴城市| 苍山县|