Php implements the method of connecting to the access database and converting to txt writing, accesstxt
This example describes how php can connect to the access database and convert it to txt. We will share this with you for your reference. The details are as follows:
The code here enables PHP to read the home location of the mobile phone and import the txt file (the mobile phone home location database is included at the end of the article)
Mdbtotxt. php code:
<? Php // php connection access test define ('table', 'shoujiguishudi '); define ('outputfile', 'output.txt'); define ('root ', str_replace ($ _ SERVER ['php _ SELF '], '', str_replace (' \ ','/',__ FILE __))); $ conn = new com ('ADODB. connection '); $ conn-> Provider = 'Microsoft. jet. oledb.4.0 '; $ conn-> Open (ROOT. '\ callerloc. mdb '); // file address $ rs = new com ('ADODB. recordset '); $ rs-> Open ('select * from '. TABLE, $ conn, 1, 1); // query TABLE $ 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; // open the file $ fp = fopen (OUTPUTFILE, "w"); echo '<table width = "100%"> <tr> '; foreach ($ rs-> Fields as $ name) {echo '<td> '. $ name-> Name. '</td>'; fwrite ($ fp, $ name-> Name. "\ t");} fwrite ($ fp, "\ r \ n"); echo '</tr>'; (;! $ Rs-> EOF; $ rs-> MoveNext () {echo '<tr>'; foreach ($ rs-> Fields as $ 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);?>
Appendix:In this exampleAccess Database.