PHP Operations Access database

Source: Internet
Author: User

To manipulate a database, you must first connect the data:
1. The following is a code fragment:
$conn = new COM ("ADODB. Connection ");
$connstr = "Driver={microsoft Access DRIVER (*.mdb)}; Dbq= ". Realpath (" Data/phone.mdb ");
$conn->open ($CONNSTR);

The following example finds related records from a database:
2. The following is a code fragment:
$rs = new COM ("ADODB. RecordSet "); To create a recordset
$rs->open ("select * from phonelist where phone= ' $mbnumber '", $conn, 1, 1);/Execute Query
if (! $rs->eof) {//To determine if a matching record exists
$id = $rs->fields (0);
$province = $rs->fields (2);
$city = $rs->fields (3);
$cardtype = $rs->fields (4);
$zipcode = $rs->fields (5);

Print Query Results
echo ' Query results:<br> ';
Echo '-------------------------------------------<br> ';
Echo ' Mobile number: '. $_post[' mbnumber '. ' <br> ';
Echo ' Province: '. Iconv ("gb2312", "Utf-8", $province->value). ' <br> ';
Echo ' City: '. Iconv ("gb2312", "Utf-8", $city->value). ' <br> ';
echo ' card type: '. Iconv ("gb2312", "Utf-8", $cardtype->value). ' <br> ';
Echo ' City area code: '. Iconv ("gb2312", "Utf-8", $zipcode->value). ' <br> ';
Echo '-------------------------------------------<br> ';
}
else {
Echo ' did not inquire about the relevant record ';/or else there is no record
}
$rs->close ()//Close Object

If you need to cycle through more than one record, this is the way:
3. The following is a code fragment:
$rs = new COM ("ADODB. RecordSet ");
$rs->open ($sql, $conn, 1, 1);
while (! $rs->eof) {
$f = $rs->fields (1);
Echo $f->value;
$rs->movenext ();
}
echo $rs->recordcount (); Total number of records taken

This article links http://www.cxybl.com/html/wlbc/Php/20120608/28915.html

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.