您好,欢迎访问一九零五行业门户网

php操作access数据库的类分享

本文介绍下,php操作access数据库的一个类,有需要的朋友参考下。代码如下:
getlist(select top 5 * from `result` where `resultno` num_rows(update `conner` set `connerip` = '222.35.142.101' where `connerno` databasepath=$databasepath; $this->username=$dbusername; $this->password=$dbpassword; $this->connect(); }function connect(){ $this->constr='driver={microsoft access driver (*.mdb)};dbq='.realpath($this->databasepath).';'; $this->link=odbc_connect($this->constr,$this->username,$this->password,sql_cur_use_odbc); if(!$this->link) echo 数据库连接失败!; return $this->link;}function query($sql){ //直接运行sql,可用于更新、删除数据 return @odbc_exec($this->link,$sql);}function fetch_array($query){ //取得当前指针处记录 return odbc_fetch_array($query);}function fetch_row($query){ //基本同fetch_array(),但只有数字索引 return odbc_fetch_row($query);}function num_rows($sql){ //返回sql查询影响到的行的数目 return odbc_num_rows($this->query($sql));}function close(){ //关闭数据库连接函数 odbc_close($this->link);}function getlist($sql){ //取得记录列表 $query=$this->query($sql); $recordlist=array(); while ($row=$this->fetch_array($query)){ $recordlist[]=$row; } return $recordlist;}}?>
以上类中使用了odbc,而不是odbc数据源。直接新建一个*.mdb文件即可使用。
附,部分常用com方式操作access代码:
open(driver={microsoft access driver (*.mdb)}; dbq=$db);?>
js调用页js.php
execute(select top 3 * from userstar where chk = 1 order by id desc);$idgb=1;while(!$rs->eof){ $gbinf[$idgb]['id'] = $rs->fields['id']->value; $gbinf[$idgb]['usname'] = $rs->fields['usname']->value; $gbinf[$idgb]['usage'] = $rs->fields['usage']->value; $gbinf[$idgb]['usprovince'] = $rs->fields['usprovince']->value; $gbinf[$idgb]['usfile'] = $rs->fields['usfile']->value; $gbinf[$idgb]['thumb'] = $rs->fields['thumb']->value; $gbinf[$idgb]['usmessage'] = $rs->fields['usmessage']->value; $rs->movenext(); $idgb++;}$rs->close();$rs = null;$uhtml='';$uhtml.='';for ($i=1; $i
另一个例子,以本文件路径确定数据库路径:
open(driver={microsoft access driver (*.mdb)}; dbq=$db);//print_r($_post);if ($_post['name'] && $_post['tel'] && $_post['addr'] && $_post['email'] && $_post['goal'] && $_post['high'] && $_post['weight'] && $_post['message']){$addsql = insert into d90usr (`name`, `tel`, `addr`, `email`, `goal`, `high`, `weight`, `message`) values ('.$_post['name'].', '.$_post['tel'].', '.$_post['addr'].', '.$_post['email'].', '.$_post['goal'].', '.$_post['high'].', '.$_post['weight'].', '.strip_tags($_post['message']).');//echo ''.$addsql;$rsadd = $conn->execute($addsql);echo '';echo '恭喜您报名成功,请等待工作人员与您联系!
';echo '返回活动首页 返回商城首页
';}?>
其它类似信息

推荐信息