search
Homephp教程php手册PHP中通过ADO调用Access数据库

我看了那篇《怎样在PHP中通过ADO调用Asscess数据库和COM程序》文章后,马上作了测试,结果失败了。伤心是不是。
怎么办?我只好去PHP官方网站求助,皇天不负有心人,终于我找到了答案——
具体的解决方法如下:
(1)进入http://php.weblogs.com/adodb,下载相应的ZIP包;同MICROSOFT公司的ADO一样,该东东用PHP实现ADO同各种各样数据库打交道(太好了,所有类型的数据库都能处理)。
(2)解包,里面文件很多,不过有用的只有ohtml.inc.php和adodb.inc.php,把它们复制到相应目录下(或是安装php4的缺省目录下c:php4peer,或是当前运行程序目录下,视include()函数而定);
(3)然后在本鸡(错误字一个,是机)的c:myphp目录下(iis下设置通过http://localhost/jhk来访问),造了一个名为test.mdb的access库,里头再造个experts的表……。为了通过DSN来访问,我把刚才的ACCESS库在DSN中取名test。
(4)运行。看着说明书我造了这么个程序:
dbtest.php,内容如下:
include( ohtml.inc.php); // load code common to ADODB
include(adodb.inc.php); // load code common to ADODB
$conn = &ADONewConnection(access); // create a connection
$conn->PConnect( est);// connect to MySQL, agora db
$sql = select name, group1 from experts;
$rs = $conn->Execute($sql);
rs2html($rs,order=2 cellpadding=3,array(Customer Name,Customer ID));


$rs->Close(); // optional
$conn->Close(); // optional
?>
然后,IE中打入:http://localhost/jhk/dbtest.php
唉!结果出来了。 令人基本满意!!
(5) 接着,我又想:还要设置DSN,烦不烦!绕过DSN应如何解决?因为在asp中,我习惯用conn.open("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("../nydatabase.mdb"))来处理mdb库,那速度快呀!
?……想了又想,看了又看……。
找找找,……,嘿嘿,终于在testdatabases.inc.php 中找到了答案! 我再把刚才的程序改编:
include( ohtml.inc.php); // load code common to ADODB
include(adodb.inc.php); // load code common to ADODB
$db = &ADONewConnection("ado_access");
print "

Connecting $db->databaseType...

";
$access = est.mdb;
$myDSN = PROVIDER=Microsoft.Jet.OLEDB.4.0;.DATA SOURCE=. $access . ;;.USER ID=;PASSWORD=;;
if (@$db->PConnect($myDSN, "", "", "")) {
print "ADO version=".$db->_connectionID->version."
";
$sql = select name, group1 from experts;
$rs = $db->Execute($sql);
rs2html($rs,order=2 cellpadding=3,array(Customer Name,Customer ID));
} else print "ERROR: Access test requires a Access database $access".
.$db->ErrorMsg();
?>
运行。
一切搞定!
本文章相关类文件本站下载地址为: http://www.phpe.net/?n=ShowClass&a=106
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version