// Name of the file$filename = 'churc.sql';// MySQL host$mysql_host = 'localhost';// MySQL username$mysql_username = 'root';// MySQL password$mysql_password = '';// Database n " /> 亚洲亚洲免费,日韩中文在线中文网在线观看,欧美日韩国产限制

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

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

復(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 /'<strong>' . $templine . '/': ' . mysql_error() . '<br /><br />');
    // Reset temp variable to empty
    $templine = '';
}
}
 echo "Tables imported successfully";
?>

php技術(shù)PHP處理SQL腳本文件導(dǎo)入到MySQL的代碼實(shí)例,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 庄浪县| 武邑县| 柘荣县| 玛沁县| 辽阳市| 南昌县| 北宁市| 隆化县| 南陵县| 福安市| 巴林左旗| 肃北| 永胜县| 肇源县| 贵阳市| 阳谷县| 吴江市| 璧山县| 佛山市| 墨脱县| 长阳| 清徐县| 施甸县| 卢龙县| 大竹县| 墨玉县| 乐平市| 万源市| 望城县| 额尔古纳市| 河池市| 安陆市| 托克托县| 钟山县| 绥芬河市| 宣城市| 利川市| 会同县| 郎溪县| 富源县| 顺平县|