This article mainly introduces how php connects to the access database and converts it to txt writing. it involves php connection, access database reading, and related operation skills for writing txt files, for more information about how to connect to the access database and write txt files in php, you can refer to the next article. This article describes how to connect to, read, and write txt files in php, for more information, see
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:
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'
'; Foreach ($ rs-> Fields as $ name) {echo'
| '. $ Name-> Name .' | '; Fwrite ($ fp, $ name-> Name. "\ t");} fwrite ($ fp, "\ r \ n"); echo'
'; (;! $ Rs-> EOF; $ rs-> MoveNext () {echo'
'; Foreach ($ rs-> Fields as $ name) {// echo'
| '. $ Name .' | '; Fwrite ($ fp, $ name. "\ t") ;}$ I ++; fwrite ($ fp, "\ r \ n"); if ($ I % 1000 = 0) echo $ I.""; Echo'
'; If ($ rs-> AbsolutePosition >=$ rs-> AbsolutePage * $ rs-> PageSize) break;} echo''; Fclose ($ fp);?>