亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

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

        字號(hào):


            通常在制作安裝程式,數(shù)據(jù)備份程序的時(shí)候會(huì)要用到這樣的代碼,我看網(wǎng)上有是有不太多,而且有些也不是很好用,有時(shí)候這種代碼直接用現(xiàn)成的可以節(jié)省很多時(shí)間,那么我就從stackoverflow轉(zhuǎn)了一個(gè)過(guò)來(lái),需要的朋友可以參考下
            代碼如下:<?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";
            ?>