国产探花免费观看_亚洲丰满少妇自慰呻吟_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";
?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吴江市| 河池市| 思南县| 汉阴县| 盱眙县| 平度市| 万载县| 宜城市| 汨罗市| 定远县| 交口县| 四子王旗| 平谷区| 那曲县| 桐柏县| 拜泉县| 商洛市| 江山市| 施秉县| 朝阳县| 衡阳市| 临洮县| 霍林郭勒市| 邯郸市| 手机| 农安县| 巴彦县| 茶陵县| 常州市| 九江县| 凤阳县| 山阴县| 珲春市| 武安市| 嘉黎县| 竹山县| 静宁县| 五华县| 彭水| 遂川县| 正宁县|