How PHP connects to an Access database summary _php tips

Source: Internet
Author: User
PHP Code:

You need to be aware that the PHP fetch path is Realpath
Copy Code code as follows:

<?php
$connstr = "Driver={microsoft Access DRIVER (*.mdb)}; Dbq= ". Realpath ("Data.mdb");
$connid =odbc_connect ($connstr, "", "", SQL_CUR_USE_ODBC);
$issuetime =date ("y-m-d h:i:s");
$sql = "INSERT INTO test values (" "," ",...)";
$result =odbc_exec ($connid, $sql);
if ($result) echo "successful";
else echo "failed";
?>


The second:

Copy Code code as follows:

? Php
Create an ADO connection
$conn = @new COM ("ADODB. Connection ") or Die (" ADO Connection Failed! ");
$connstr = "Driver={microsoft Access DRIVER (*.mdb)}; Dbq= ". Realpath ("Temp/tempdata.mdb");
$conn->open ($CONNSTR);

To create a recordset query
$rs = @new COM ("ADODB. RecordSet ");
$rs->open ("SELECT * from Blog_content", $conn, 1, 3);
echo $rs->fields["Log_title"]->value; Output Log_title Field
echo "<br/>";
$rs->movenext (); Move the recordset pointer down
echo $rs->fields["Log_title"]->value;
$rs->close ();
?>


Method three: With ODBC, in the ODBC Governance for Db1.mdb to build a system data source (generally require server permissions, not recommended)

Name: Dbdsn (You can set it yourself)
Driver: Microsoft Access Driver (*. MDB)

Code:
Copy Code code as follows:

$Conn = Odbc_connect ("Dbdsn", "admin", "123"); Connecting to a data source
$Doquery =odbc_exec ($Conn, "select * from table name where Condition");//Execute Query


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.