Php implements the method of connecting to the access database and converting to txt writing, accesstxt

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.