Home  >  Article  >  Backend Development  >  Three PHP methods to connect to access database_PHP tutorial

Three PHP methods to connect to access database_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:13883browse

One is to use php's pdo, and the other is to use odbc and com interfaces to connect to the access database.
Use pdo to connect to the access database

Copy the code The code is as follows:

$path ="f:fontwww.jb51 .netspiderresult.mdb";
$conn = new pdo("sqlite:$path");
if( $conn )
{
echo ('connection pdo success');
}
else
{
echo ('cnnection pdo fail ,plase check database server!');
}

Use odbc_connect to connect to the database
Copy code The code is as follows:

$conn = odbc_connect("dbdsn","admin","123"); //Connect to data source
$doquery=odbc_exec($conn,"select * from table name where condition");//Execute query


Use the com interface to connect to the access database
$conn=new com("adodb.connection");
$dsn="driver={microsoft access driver (*.mdb)} ;dbq=".realpath("path/db1.mdb");
$conn->open($dsn);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825153.htmlTechArticleOne is to use php's pdo, and the other is odbc, com interface to connect to the access database. Use pdo to connect to the access database. Copy the code. The code is as follows: $path ="f:fontwww.jb51.netspiderresult...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn