国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

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

2024-05-04 23:22:15
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

<?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";
?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长春市| 公主岭市| 和顺县| 仙居县| 扶沟县| 南郑县| 阿拉善右旗| 太仆寺旗| 斗六市| 重庆市| 绍兴县| 卓资县| 安福县| 洪江市| 承德县| 陵水| 岫岩| 台湾省| 罗平县| 钦州市| 十堰市| 玉环县| 凤冈县| 全椒县| 化隆| 苍梧县| 温州市| 元氏县| 鹰潭市| 嘉黎县| 洪洞县| 钟祥市| 安化县| 房山区| 永新县| 达尔| 治县。| 邯郸市| 嘉善县| 和平区| 内黄县|