linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘建议留言网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > php >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·PHP生成静态页面的一些经验
·PHP无限分类与树型论坛的实现方
·php5学习笔记
·入门级PHP程序员面试题
·PHP 和 MySQL初学入门
·PHP入门速成
·vim的代码折叠
·文件下载统计php编程代码
·如何建立自己的新闻发布系统
·织梦CMS中文转换拼音函数研究
·Windows下Apache+Tomcat+MySQL
·PHP初学者头疼问题总结
·Cookie及其使用详细介绍
·生成sessionid和随机密码的例子
·使用无限生命期Session的方法
最新文章
·PHP入门速成
·用php实现广告轮播
·Zend Optimizer 问题浅析
·功能强大的CGI语言----PHP3
·用Session对Web页面进行保护
·PHP--进行模块化设计
·如何将PHP的结果输出到非PHP页
·如何开发一个虚拟域名系统
·PHP4调用自己编写的COM组件
·简单的页面缓冲技术(三)
·简单的页面缓冲技术(二)
·简单的页面缓冲技术(一)
·用Socket发送电子邮件(二)
·用Socket发送电子邮件(一)
·PHP/MySQL 购物车
Google
 
php+odbc+access数据库操作函数
[ 作者:  加入时间:2007-11-22 14:36:40  来自:Linux联盟收集整理 ]
前些天下载了adodb,想用adodb连access数据库,后来连是连上了,不过不能更新和插入记录,也不知道为什么到现在还没人给我回答那个苦恼的问题,后来就放弃了adodb,使用php自己的odbc,但是使用很不方便,就写下了下面这些函数,还没有封装成类,希望能够为有同样问题的朋友一些帮助 Z2WLinux联盟
   Z2WLinux联盟
  <?php Z2WLinux联盟
  /* Z2WLinux联盟
   * @ access class Z2WLinux联盟
   * insert,update,delete record Z2WLinux联盟
   * version 1.0 Z2WLinux联盟
   * date 2005.6 Z2WLinux联盟
   * power by Samsun Manzalo (34n 猪八戒) Z2WLinux联盟
   * Z2WLinux联盟
   */ Z2WLinux联盟
   Z2WLinux联盟
  //==================================== Z2WLinux联盟
  // insert record Z2WLinux联盟
  // 插入记录 Z2WLinux联盟
  //==================================== Z2WLinux联盟
  function insRd($table,$field){ Z2WLinux联盟
   $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb"; Z2WLinux联盟
   $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); Z2WLinux联盟
   $tmpA = explode(',',$field); Z2WLinux联盟
   $ins = ''; Z2WLinux联盟
   for($i=0;$i<count($tmpA);$i++){ Z2WLinux联盟
   $ins.= "'".$_POST[$tmpA[$i]]."',"; Z2WLinux联盟
   } Z2WLinux联盟
   $ins = substr($ins,0,-1); Z2WLinux联盟
   $sql = "INSERT INTO ".$table." (".$field.") VALUES (".$ins.")"; Z2WLinux联盟
   //echo $sql;exit; Z2WLinux联盟
   $query = @odbc_do($connid,$sql); Z2WLinux联盟
  } Z2WLinux联盟
   Z2WLinux联盟
   Z2WLinux联盟
  //==================================== Z2WLinux联盟
  // get one record detail Z2WLinux联盟
  // 取得当条记录详细信息 Z2WLinux联盟
  //==================================== Z2WLinux联盟
  function getInfo($table,$field,$id,$colnum){ Z2WLinux联盟
   $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb"; Z2WLinux联盟
   $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); Z2WLinux联盟
   $sql = "select * from ".$table." where ".$field."=".$id; Z2WLinux联盟
   $query = @odbc_do($connid,$sql); Z2WLinux联盟
   Z2WLinux联盟
   if(odbc_fetch_row($query)){ Z2WLinux联盟
   for($i=0;$i<$colnum;$i++){ Z2WLinux联盟
   $info[$i] = odbc_result($query,$i+1); Z2WLinux联盟
   } Z2WLinux联盟
   } Z2WLinux联盟
   return $info; Z2WLinux联盟
  } Z2WLinux联盟
   Z2WLinux联盟
   Z2WLinux联盟
  //==================================== Z2WLinux联盟
  // get record list Z2WLinux联盟
  // 取得记录列表 Z2WLinux联盟
  //==================================== Z2WLinux联盟
  function getList($table,$field,$colnum,$condition,$sort="order by id desc"){ Z2WLinux联盟
   $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb"; Z2WLinux联盟
   $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); Z2WLinux联盟
   $sql = "select * from ".$table." ".$condition." ".$sort; Z2WLinux联盟
   $query = @odbc_do($connid,$sql); Z2WLinux联盟
   //echo $sql."<br>"; Z2WLinux联盟
   $i = 0; Z2WLinux联盟
   while(odbc_fetch_row($query)){ Z2WLinux联盟
   $rdList[$i] = getInfo($table,$field,odbc_result($query,1),$colnum); Z2WLinux联盟
   $i++; Z2WLinux联盟
   } Z2WLinux联盟
   return $rdList; Z2WLinux联盟
  } Z2WLinux联盟
   Z2WLinux联盟
   Z2WLinux联盟
  //==================================== Z2WLinux联盟
  // get record list condition Z2WLinux联盟
  // 取得记录列表 Z2WLinux联盟
  //==================================== Z2WLinux联盟
  function getFieldList($table,$field,$fieldnum,$condition="",$sort=""){ Z2WLinux联盟
   $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb"; Z2WLinux联盟
   $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); Z2WLinux联盟
   $sql = "select ".$field." from ".$table." ".$condition." ".$sort; Z2WLinux联盟
   $query = @odbc_do($connid,$sql); Z2WLinux联盟
   //echo $sql."<br>"; Z2WLinux联盟
   $i = 0; Z2WLinux联盟
   while(odbc_fetch_row($query)){ Z2WLinux联盟
   for($j=0;$j<$fieldnum;$j++){ Z2WLinux联盟
   $info[$j] = odbc_result($query,$j+1); Z2WLinux联盟
   } Z2WLinux联盟
   $rdList[$i] = $info; Z2WLinux联盟
   $i++; Z2WLinux联盟
   } Z2WLinux联盟
   return $rdList; Z2WLinux联盟
  } Z2WLinux联盟
   Z2WLinux联盟
  //==================================== Z2WLinux联盟
  // update record Z2WLinux联盟
  // 更新记录 Z2WLinux联盟
  //==================================== Z2WLinux联盟
  function updateInfo($table,$field,$id,$set){ Z2WLinux联盟
   $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb"; Z2WLinux联盟
   $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); Z2WLinux联盟
   $sql = "update ".$table." set ".$set." where ".$field."=".$id; Z2WLinux联盟
   $query = @odbc_do($connid,$sql); Z2WLinux联盟
  } Z2WLinux联盟
   Z2WLinux联盟
   Z2WLinux联盟
  //==================================== Z2WLinux联盟
  // record delete Z2WLinux联盟
  // 删除记录 Z2WLinux联盟
  //==================================== Z2WLinux联盟
  function delRd($table,$field,$id){ Z2WLinux联盟
   $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb"; Z2WLinux联盟
   $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); Z2WLinux联盟
   $sql = "delete from ".$table." where ".$field."=".$id; Z2WLinux联盟
   $query = @odbc_do($connid,$sql); Z2WLinux联盟
  } Z2WLinux联盟
   Z2WLinux联盟
   Z2WLinux联盟
  //==================================== Z2WLinux联盟
  // record delete cat Z2WLinux联盟
  // 删除记录(条件) Z2WLinux联盟
  //==================================== Z2WLinux联盟
  function delOrRd($table,$condition){ Z2WLinux联盟
   $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb"; Z2WLinux联盟
   $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); Z2WLinux联盟
   $sql = "delete from ".$table." where ".$condition; Z2WLinux联盟
   $query = @odbc_do($connid,$sql); Z2WLinux联盟
  } Z2WLinux联盟
   Z2WLinux联盟
   Z2WLinux联盟
  //==================================== Z2WLinux联盟
  // count record Z2WLinux联盟
  // 取得记录数 Z2WLinux联盟
  //==================================== Z2WLinux联盟
  function countRd($table,$condition=""){ Z2WLinux联盟
   $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb"; Z2WLinux联盟
   $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); Z2WLinux联盟
   $sql = "select count(*) as num from ".$table." ".$condition; Z2WLinux联盟
   $query = @odbc_do($connid,$sql); Z2WLinux联盟
   odbc_fetch_row($query); Z2WLinux联盟
   $num = odbc_result($query,1); Z2WLinux联盟
   return $num; Z2WLinux联盟
  } Z2WLinux联盟
   Z2WLinux联盟
  ?> Z2WLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·用PHP与XML联手进行网站编程  (2007-11-22 14:34:59)
 ·PHP SOCKET 技术研究  (2007-11-22 14:34:33)
 ·php分别做为cgi和module来运行的配置  (2007-11-22 14:32:59)
 ·php中数据的批量导入(csv文件)  (2007-11-22 14:32:26)
 ·BS结构中使用PHP访问ORACLE LOB  (2007-11-22 14:31:59)
 ·PHP的一个完整SMTP类(解决邮件服务器需要验证时的问题)  (2007-11-22 14:24:00)
 ·用PHP生成PDF文件 with FPDF  (2007-11-22 14:23:31)
 ·在同一窗体中使用PHP来处理多个提交任务  (2007-11-22 14:22:40)
 ·PHP中实现图片的锐化  (2007-11-22 14:22:05)
 ·在Zeus Web Server中安装PHP语言支持  (2007-11-22 14:12:43)