PHP技术将Sql文件导入到MySql(2)
来源:互联网 责任编辑:栏目编辑 发表时间:2013-07-01 13:24 点击:次
$sql = str_replace("r", "n",$sql);
$ret = array();
$num = 0;
foreach(explode(";n", trim($sql)) as $query) {
$queries = explode("n", trim($query));
foreach($queries as $query) {
$ret[$num] .= $query[0] == '#' ? '' : $query;
}
$num++;
}
unset($sql);
foreach($ret as $query) {
$query = trim($query);
if($query) {
if(substr($query, 0, 12) == 'CREATE TABLE') {
$name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\1", $query);
echo '创建表 '.$name.' ... <font color="#0000EE">成功</font><br />';
mysql_query(createtable($query, $dbcharset));
$tablenum++;
} else {
mysql_query($query);
}
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>