搜索
首页php教程php手册php 导入.sql文件到mysql数据库

php 导入.sql文件到mysql数据库

Jun 13, 2016 am 10:07 AM
mysqlphpset导入教程数据库文件

php 导入.sql文件到mysql数据库

php教程 导入.sql文件到mysql教程数据库教程

set_time_limit(0); //设置超时时间为0,表示一直执行。当php在safe mode模式下无效,此时可能会导致导入超时,此时需要分段导入
$db =  new mysql($location['host'],$location['hostname'],$location['hostpass'],$location['table'],"utf8",$location['ztime']);  
$fp = @fopen($sql, "r") or die("不能打开sql文件 $sql");//打开文件
while($sql=getnextsql()){
    mysql_query($sql);
}
//echo "用户数据导入完成!";
fclose($fp) or die("can't close file $file_name");//关闭文件

//从文件中逐条取sql
function getnextsql() {
    global $fp;
    $sql="";
    while ($line = @fgets($fp, 40960)) {
        $line = trim($line);
        //以下三句在高版本php中不需要,在部分低版本中也许需要修改
        //$line = str_replace("\\","\",$line);
        //$line = str_replace("'","'",$line);
        //$line = str_replace("\r\n",chr(13).chr(10),$line);
        //$line = stripcslashes($line);
        if (strlen($line)>1) {
            if ($line[0]=="-" && $line[1]=="-") {
                continue;
            }
        }
        $sql.=$line.chr(13).chr(10);
        if (strlen($line)>0){
            if ($line[strlen($line)-1]==";"){
                break;
            }
        }
    }
    return $sql;
}
?>

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。