请问如何把文本文件导入到MYSQL中 送100分 MySql 下的命令load data local infile "c:\\这样的.TXT " into table testing (ip,ck) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 load data local infile "http://www.rjqimo.com/ipdata.txt" into table testing (ip,ck)我去试下看...先谢谢楼上了 <?$a = file('data.txt');foreach ($a as $k){ $s = explode(' ',$k); echo '<pre>'; print_r ($s); echo '</pre>'; }?> 服务器不支持MYSQL load data 命令怎么办啊???? <? //main $hostname = "localhost"; $user = "root"; $pw= "root"; $database= "yourdatabase"; $db = new PDO('mysql:host='.$hostname.';dbname='.$database, $user, $pw); $db->exec("SET NAMES 'utf8'"); $fhand = fopen("http://127.0.0.1/php/data.txt","r"); $todata = array(); while($lineinfo = getinfo()){ $lineinfo=iconv("GB2312","UTF-8",$lineinfo); $lineinfo = explode(" ", $lineinfo); $todata[]= $lineinfo; } $todata=daddslashes($todata); savetodatabase($todata,$db); function savetodatabase($todata,$db){ $sql="INSERT INTO `yourtable` (`one`,`two`,`three`,`four`) VALUES"; foreach($todata as $array){ $sql.="("; foreach($array as $value){ $sql.="'".$value."',"; } $sql=substr($sql, 0, -1); $sql.="),"; } $sql=substr($sql, 0, -1); //echo $sql; echo $db->exec($sql); } function getinfo(){ global $fhand; if(feof($fhand)){ return false; fclose($fhand); } $line = fgets($fhand); return $line; } function daddslashes($string, $force = 0) { !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc()); if(!MAGIC_QUOTES_GPC || $force) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = daddslashes($val, $force); } } else { $string = addslashes($string); } } return $string; }?> 反序列化打印不了好奇怪 这个正则怎么写? 如何防止打开页面自动下载 PHP分割失败,郁闷啊,苦逼的还在加班调试 再问:关于静态页面访问IP记数的问题! 关于图片连续滚动问题,急,线上等! 丢个打印分页的问题,请各位提个意见 在使用db库时,如果要双重循环,应该怎么办? 每一个数字标识一个网页,如:http://www.meihua.info/a/68772,请问这是怎么实现的? PHP有些代码无法解析 PHP web service 如何使用 disco文件 下载类
$s = explode(' ',$k);
echo '<pre>';
print_r ($s);
echo '</pre>';
}?>
//main
$hostname = "localhost";
$user = "root";
$pw= "root";
$database= "yourdatabase";
$db = new PDO('mysql:host='.$hostname.';dbname='.$database, $user, $pw);
$db->exec("SET NAMES 'utf8'");
$fhand = fopen("http://127.0.0.1/php/data.txt","r");
$todata = array();
while($lineinfo = getinfo()){
$lineinfo=iconv("GB2312","UTF-8",$lineinfo);
$lineinfo = explode(" ", $lineinfo);
$todata[]= $lineinfo;
}
$todata=daddslashes($todata);
savetodatabase($todata,$db);
function savetodatabase($todata,$db){
$sql="INSERT INTO `yourtable` (`one`,`two`,`three`,`four`) VALUES";
foreach($todata as $array){
$sql.="(";
foreach($array as $value){
$sql.="'".$value."',";
}
$sql=substr($sql, 0, -1);
$sql.="),";
}
$sql=substr($sql, 0, -1);
//echo $sql;
echo $db->exec($sql);
}
function getinfo(){
global $fhand;
if(feof($fhand)){
return false;
fclose($fhand);
}
$line = fgets($fhand);
return $line;
}
function daddslashes($string, $force = 0)
{
!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
if(!MAGIC_QUOTES_GPC || $force)
{
if(is_array($string))
{
foreach($string as $key => $val)
{
$string[$key] = daddslashes($val, $force);
}
}
else
{
$string = addslashes($string);
}
}
return $string;
}
?>