php odbc access数据库操作函数,在windows下测试…
2008-02-23 06:26:46来源:互联网 阅读 ()
前些天下载了adodb,想用adodb连access数据库,后来连是连上了,不过不能更新和插入记录,也不知道为什么到现在还没人给我回答那个苦恼的问题,后来就放弃了adodb,使用php自己的odbc,但是使用很不方便,就写下了下面这些函数,还没有封装成类,希望能够为有同样问题的朋友一些帮助
<?php
/*
* @ access class
* insert,update,delete record
* version 1.0
* date 2005.6
* power by Samsun Manzalo (34n 猪八戒)
* www.knowsky.com
*/
//====================================
// insert record
// 插入记录
//====================================
function insRd($table,$field){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");
$tmpA = explode(',',$field);
$ins = '';
for($i=0;$i<count($tmpA);$i ){
$ins.= "'".$_POST[$tmpA[$i]]."',";
}
$ins = substr($ins,0,-1);
$sql = "INSERT INTO ".$table." (".$field.") VALUES (".$ins.")";
//echo $sql;exit;
$query = @odbc_do($connid,$sql);
}
//====================================
// get one record detail
// 取得当条记录详细信息
//====================================
function getInfo($table,$field,$id,$colnum){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");
$sql = "select * from ".$table." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
if(odbc_fetch_row($query)){
for($i=0;$i<$colnum;$i ){
$info[$i] = odbc_result($query,$i 1);
}
}
return $info;
}
//====================================
// get record list
// 取得记录列表
//====================================
function getList($table,$field,$colnum,$condition,$sort="order by id desc"){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");
$sql = "select * from ".$table." ".$condition." ".$sort;
$query = @odbc_do($connid,$sql);
//echo $sql."<br>";
$i = 0;
while(odbc_fetch_row($query)){
$rdList[$i] = getInfo($table,$field,odbc_result($query,1),$colnum);
$i ;
}
return $rdList;
}
//====================================
// get record list condition
// 取得记录列表
//====================================
function getFieldList($table,$field,$fieldnum,$condition="",$sort=""){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");
$sql = "select ".$field." from ".$table." ".$condition." ".$sort;
$query = @odbc_do($connid,$sql);
//echo $sql."<br>";
$i = 0;
while(odbc_fetch_row($query)){
for($j=0;$j<$fieldnum;$j ){
$info[$j] = odbc_result($query,$j 1);
}
$rdList[$i] = $info;
$i ;
}
return $rdList;
}
//====================================
// update record
// 更新记录
//====================================
function updateInfo($table,$field,$id,$set){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");
$sql = "update ".$table." set ".$set." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
}
//====================================
// record delete
// 删除记录
//====================================
function delRd($table,$field,$id){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");
$sql = "delete from ".$table." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
}
//====================================
// record delete cat
// 删除记录(条件)
//====================================
function delOrRd($table,$condition){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");
$sql = "delete from ".$table." where ".$condition;
$query = @odbc_do($connid,$sql);
}
//====================================
// count record
// 取得记录数
//====================================
function countRd($table,$condition=""){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");
$sql = "select count(*) as num from ".$table." ".$condition;
$query = @odbc_do($connid,$sql);
odbc_fetch_row($query);
$num = odbc_result($query,1);
return $num;
}
?>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:php用流方式制作缩略图
下一篇:PHP IPwhois类
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash