這裡的代碼實現PHP讀取手機歸屬地 並導入txt文件的功能(文章末尾附手機歸屬地 數據庫)
mdbtotxt.php代碼:
代碼如下 復制代碼<?php
//php連接access測試
define('TABLE','shoujiguishudi');
define('OUTPUTFILE','output.txt');
define('ROOT',str_replace($_SERVER['PHP_SELF'],'',str_replace('\\','/',__FILE__)));
$conn=newcom('adodb.connection');
$conn->Provider='microsoft.jet.oledb.4.0';
$conn->Open(ROOT.'\\callerloc.mdb');//文件地址
$rs=newcom('adodb.recordset');
$rs->Open('SELECT * FROM '.TABLE,$conn, 1, 1);//查表
$i= 0;
$page=1;
if(!empty($_GET['page'])){
$page=$_GET['page'];
if($page<1)$page=1;
if($page>$rs->PageCount)$page=$rs->PageCount;
}
$rs->AbsolutePage=$page;
//打開文件
$fp=fopen(OUTPUTFILE,"w");
echo'<table width="100%"><tr>';
foreach($rs->Fieldsas$name){
echo'<td>'.$name->Name.'</td>';
fwrite($fp,$name->Name."\t");
}
fwrite($fp,"\r\n");
echo'</tr>';
for(;!$rs->EOF;$rs->MoveNext()){
echo'<tr>';
foreach($rs->Fieldsas$name){
//echo '<td>'.$name.'</td>';
fwrite($fp,$name."\t");
}
$i++;
fwrite($fp,"\r\n");
if($i%1000==0)
echo$i."<br>";
echo'</tr>';
if($rs->AbsolutePosition>=$rs->AbsolutePage*$rs->PageSize)
break;
}
echo'</tale>';
fclose($fp);
?>