足球游戏_中国足彩网¥体育资讯$

PHP处理SQL脚本文件导入到MySQL的代码实例
来源:易贤网 阅读:692 次 日期:2014-08-22 11:08:05
温馨提示:易贤网小编为您整理了“PHP处理SQL脚本文件导入到MySQL的代码实例”,方便广大网友查阅!

通常在制作安装程式,数据备份程序的时候会要用到这样的代码,我看网上有是有不太多,而且有些也不是很好用,有时候这种代码直接用现成的可以节省很多时间,那么我就从stackoverflow转了一个过来,需要的朋友可以参考下

代码如下:<?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";

?>

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看网络编程
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标