用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > php教程

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

时间:2015-01-23  来源:西部数据  作者:西部数据
  1. set_time_limit(0); //设置超时时间为0,表示一直执行。当php在safe mode模式下无效,此时可能会导致导入超时,此时需要分段导入 
  2. $db =  new mysql($location['host'],$location['hostname'],$location['hostpass'],$location['table'],"utf8",$location['ztime']);   
  3. $fp = @fopen($sql"r"or die("不能打开sql文件 $sql");//打开文件 
  4. while($sql=getnextsql()){ 
  5.     mysql_query($sql); 
  6. //echo "用户数据导入完成!"; 
  7. fclose($fpor die("can't close file $file_name");//关闭文件 
  8. //从文件中逐条取sql 
  9. function getnextsql() { 
  10.     global $fp
  11.     $sql=""
  12.     while ($line = @fgets($fp, 40960)) { 
  13.         $line = trim($line); 
  14.         //以下三句在高版本php中不需要,在部分低版本中也许需要修改 
  15.         //$line = str_replace("\\","\",$line); 
  16.         //$line = str_replace("'","'",$line); 
  17.         //$line = str_replace("\r\n",chr(13).chr(10),$line); 
  18.         //$line = stripcslashes($line); 
  19.         if (strlen($line)>1) { 
  20.             if ($line[0]=="-" && $line[1]=="-") { 
  21.                 continue
  22.             } 
  23.         } 
  24.         $sql.=$line.chr(13).chr(10); 
  25.         if (strlen($line)>0){ 
  26.             if ($line[strlen($line)-1]==";"){ 
  27.                 break;//开源代码phpfensi.com 
  28.             } 
  29.         } 
  30.     } 
  31.     return $sql
  32. }
来顶一下
返回首页
返回首页
推荐资讯
WiFi太不安全:7岁女孩11分钟内入侵公共网络 WiFi太不安全:7岁女孩11分钟内入侵近期刚刚发布研究说WiFi网络能获得人们手机里多少私人信息,
不服跑个分?人工智能也出现“刷分”乱象 不服跑个分?人工智能也出现“刷分2014年,人工智能领域突然爆发,成为了科研和科技创业的热门
相关文章
    无相关信息
栏目更新
栏目热门