3-adodb数据操作.docx_第1页
3-adodb数据操作.docx_第2页
3-adodb数据操作.docx_第3页
3-adodb数据操作.docx_第4页
3-adodb数据操作.docx_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、ADODB 是 Active Data Objects Data Base 的简称,它是一种 PHP 存取数据库的中间函式组件。PHP 在数据库的支持上是很令人称道的,几乎所有的知名数据库系统都有对应的函数群支持,而且支持的很完整。但很不幸的,每一群数据库支持函数无论在名称或参数结构上,都有很大的差异,这使得PHP的系统开发者在面临更换数据库时,总会觉得痛苦万分。难道这个问题就没有解决方法吗?呵呵,当然有,答案就是我现在要介绍的 ADODB 这个PHP对象。ADODB提供了完整的方法和属性让工程师去控制数据库系统,更棒的是你只要记得它的功能就好了,因为不同的数据库系统,只要修改一个属性值就可以了,ADODB会自动依据设定取用正确的PHP函数。此外,最多再配合数据库系统修改修改SQL指令,你的PHP系统就可以在最短的时间内更换到另一个数据库系统了,如果在撰写程序时,对SQL指令能做妥善规划,那就更快了。2、Databases Supported3、ADODB下载与安装PConnect(localhost,root,bbs);$conn-Execute(set names gbk);/4.执行$recordSet = $conn-Execute(select * from guest);/5.处理结果集while (!$recordSet-EOF) print $recordSet-fields1. .$recordSet-fields2.; $recordSet-MoveNext();/6.关闭资源$recordSet-Close();$conn-Close();?还可以通过数据源名称(DNS)的方式进行连接。$conn = ADONewConnection(mysql:/root:localhost/bbs); 4、函数介绍PConnect(localhost,root,bbs);$conn = ADONewConnection(mysql:/root:localhost/bbs);$conn-execute(set names gbk);/4.执行$recordSet = $conn-Execute(select * from guest where id=?,2);/5.处理结果集while (!$recordSet-EOF) print $recordSet-fields1. .$recordSet-fields2.; $recordSet-MoveNext();/6.关闭资源$recordSet-Close();$conn-Close();?查询出select * from guest where id=2的结果。控制结果集函数:生成HTML表格函数分页功能函数错误处理与调试example1数据库连接类ConnDB.class.phpclass ConnDBvar $dbType;var $host;var $user;var $pwd;var $dbName;var $debug;/false不显示侦错信息,反之,显示var $conn;function _construct($dbType,$host,$user,$pwd,$dbName,$debug=false)$this-dbType = $dbType;$this-host = $host;$this-user = $user;$this-pwd = $pwd;$this-dbName = $dbName;$this-debug = $debug;/实现数据库的连接并返回连接对象(个人理解可以说返回ADODB对象)function getConnId()include_once(adodb/adodb.inc.php);if($this-dbType = mysql | $this-dbType = mssql)if($this-dbType = mysql)$this-conn = NewADOConnection(mysql);/创建ADODB对象,声明数据库类型为mysqlelse$this-conn = NewADOConnection(mssql);$this-conn-Connect($this-host,$this-user,$this-pwd,$this-dbName);else if($this-dbType = access)$this-conn = NewADOConnection(access);$this-conn-Connect(Driver=Microsoft Access Driver (*.mdb);Dbq=.$this-dbName.;Uid=.$this-user.;Pwd=.$this-pwd.;);$this-conn-Execute(set names utf-8);if($this-dbType = mysql)$this-conn-debug = $this-debug;return $this-conn;function closeConnId() /关闭与数据库的连接$this-conn-Disconnection();数据库操作类AdminDB.class.phpclass AdminDBvar $sqlStr;var $conn;var $sqlType;var $rs;var $array;function execSQL($sqlStr,$conn)$rs = $conn-Execute($sqlStr);$sqlType = strtolower(substr(trim($sqlStr),0,6); /strtolower() 函数把字符串转换为小写。if($sqlType = select)$array = $rs-GetRows(); / 类似mysql_fetch_array函数返回的数组if(count($array) = 0 | $rs = false)return false;elsereturn $array;else if($sqlType = update|$sqlType = insert|$sqlType = delete)if($rs)return true;elsereturn false;system.inc.phpgetConnId();$admindb=new AdminDB();index.phpexecSQL($sql, $conn);for($i=0;$i分页类sepPage.class.phpnowPage = $nowPage;$this-pageSize = $pageSize; /页数$this-conn = $conn;$this-sqlStr = $sqlStr;$this-rs = $this-conn-PageExecute($this-sqlStr,$this-pageSize,$this-nowPage);$this-array = $this-rs-GetRows(); /获取记录数if(count($this-array) = 0 | $this-rs = false)return false;elsereturn $this-array;function ShowPage($contentname,$utits,$anothersearchstr,$class)$allrs=$this-conn-Execute($this-sqlStr);$record=count($allrs-GetRows();$pagecount=ceil($record/$this-pageSize);$str.=共有.$contentname. .$record. .$utits. 每页显示 .$this-pageSize. .$utits. 第 .$this-rs-AbsolutePage(). 页/共 .$pagecount. 页;$str.=    if(!$this-rs-AtFirstPage()$str.=首页;else$str.=首页;$str.= if(!$this-rs-AtFirstPage()$str.=rs-AbsolutePage()-1).$anothersearchstr. class=.$class.上一页;else$str.=上一页;$str.= if(!$this-rs-AtLastPage()$str.=rs-AbsolutePage()+1).$anothersearchstr. class=.$class.下一页;else$str.=下一页;$str.= if(!$this-rs-AtL

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论