php access 数据连接与读取保存编辑数据的实现代码
脚本之家会给出一个php+access的留言本源码,大家可以参考下。基本上对php access的操作就熟悉了。
代码如下:
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("www.jb51.net/db.mdb");
//与access连接要用到com接口了。
$conn->Open($connstr);
$rs = new com("ADODB.RecordSet");
//数据查询并显示出来
$rs->Open("select * from szd_t",$conn,1,1);
while(! $rs->eof) {
$f = $rs->Fields(1);
echo $f->value;
$rs->MoveNext();
}
//下面来看一下php access数据库教程保存
$sql ="insert into szd_t(title)values('www.jb51.net')";
$rs->Open( $sql );
echo '保存成功';
//php access数据库编辑
$sql ="Update szd_t set title='jb51.net' where id=".$_GET['id'];
$rs->Open( $sql );
echo '编辑成功';
//删除数据
$sql ="delete from szd_t where id=".$_GET['id'];
php连接Access数据库的三种方法
最近想把一个asp的网站改成php的,无奈空间不支持mysql数据库,只好用access数据库了,但以前都是用的php+mysql,php+access数据库编程还真没有做过.
感谢党,感谢cctv,感谢搜索引擎,这不找到一编不错的文章,特转过来和大家分享.
在PHP中连接Access有如下3种方式。
(1)创建系统数据源,用PHP提供的ODBC函数即可。
(2)同样可以使用PHP的ODBC函数,但不创建数据源。
开放数据库连接(Open DateBase Conection,ODBC)是Windows Open Server(开放服务)API(WOSA)产品之一。一个数据源是对数据库的一个命名连接。对于应用程序要连接的不同类型的数据库,都需要一个ODBC驱动程序。ODBC API主要是为客户/服务器的RDBMS使用设计的,但是ODBC驱动程序也可以用于连接桌面数据库文件、工作表和平面文件。ODBC使用Odbcinst.dll库来设置和清除数据源。Odbcad32.exe是一个用于建立ODBC数据源的独立的32位可执行应用程序,在控制面板中有其对应的图标Control Panel。
ODBC驱动管理程序为数据源打开ODBC驱动程序并将SQL语句传送给驱动程序。在客户/服务器RDBMS处理完一个select查询后,ODBC驱动程序将值返回给应用程序。当执行一个insert、update或delete语句时,驱动程序返回查询所影响的行数。 phperz.com
下面介绍PHP使用ODBC连接Access数据库的方法。用$connstr="DRIVER= Microsoft Access Driver (*.mdb)来设置数据驱动,函数realpath()用来取得数据库的相对路径。利用该方法连接Access数据库主要应用到PHP的odbc_connect()函数,该函数声明如下: www.phperz.com
代码如下:
resourse odbc_connect( string dsn, string user, string password [, int cursor_type])
dsn:系统dsn名称。
user:数据库服务器某用户名。
password:数据库服务器某用户密码。
cursor_type:游标类型。
代码如下:
代码如下:
$connstr="DRIVER=Microsoft Access Driver (*.mdb);
DBQ=".realpath("bookinfo.mdb");
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC );
(3)使用微软的ADODB数据库驱动。ActiveX Data Objects(ADO)是Microsoft开放数据库应用程序的数据库访问技术。它被设计用来同新的数据访问层OLE DB Provider一起协同工作,提供通用数据访问(Universal Date Access)。OLE DB是一个低层的数据访问接口,用它可以访问各种数据源,包括传统的关系型数据库、电子邮件系统及自定义的商业对象。ADO技术大大简化了OLE DB的操作,因为ADO封装了OLE DB程序中使用的大量COM接口,所以ADO是一种高层的访问技术。 php程序员站
ADO技术基于通用对象模型(COM),它提供了多种语言的访问技术。PHP是通过预先定义类COM来使用ADO方法操纵Access数据库的。该类详细说明如下: www.phperz.com
代码如下:
string com::com( string module_name [, string server_name [, int codepage]])
module_name:被请求组件的名字或class-id。 www~phperz~com
server_name:DCOM服务器的名字。
Codepage:指定用于将PHP字符串转换成UNICODE字符串的代码页,反之亦然。该参数的取值有CP_ACP、CP_MACCP、CP_OEMCP、CP_SYMBOL、CP_THREAD_ACP、CP_UTF7和CP_UTF8。
PHP利用com类并使用ADO方法访问数据库的代码如下:
[code]
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("bookinfo.mdb ");
$conn->Open($connstr);
这篇是别的网友发的一篇文章。结合下,最后脚本之家会给出一个php+access的留言本源码,大家可以参考下。基本上对php access的操作就熟悉了。
虽然很少用PHP链接ACCESS,但偶尔用来导导数据,还是挺不错的
代码如下:
/*
创建ADO连接
*/
$conn = @new COM("ADODB.Connection") or die ("ADO Connection faild.");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("DATUM/cnbt.mdb");
$conn->Open($connstr);
/*
创建记录集查询
*/
$rs = @new COM("ADODB.RecordSet");
$rs->Open("select * from dbo_dirs",$conn,1,3);
/*
循环读取数据
*/
while(!$rs->eof){
echo "$rs->Fields["title"]->Value;
echo "
";
$rs->Movenext(); //将记录集指针下移
}
$rs->close();
?>
函数描述及例子
虽然很少用PHP链接ACCESS,但偶尔用来导导数据,还是挺不错的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
