query('set names utf8');//设置编码 echo "正在执行导入操作"; while($SQL = GetNextSQL()){ if(!$pdo->query($SQL)){ echo "执行出错"; echo "SQL语句为".$SQL; } } echo "导入完成"; fclose($fp) or die("can't close file");//关闭文件 mysql_close(); //从文件中逐条取sql function GetNextSQL(){ global $fp; $sql=""; while($line = @fgets($fp,40960)){ $line = trim($line); $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; }