PHP读取access 数据库的部分方法实例
最好是在windows的环境的php使用,在linux上诸多问题。
<?php //读取mdb数据库例程
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../mydata.mdb");
$conn->Open($connstr);
$rs = new com("ADODB.RecordSet");
$rs->Open("select * from userinfo",$conn,1,1);
while(! $rs->eof) {
$f = $rs->Fields(1);
echo $f->value;
echo " ". $rs->Fields(2)->value;
$rs->MoveNext();
}
?>
2、PHP一般数据写入方法:
<?php
$connstr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("../chen416/mydata.mdb");
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC);
$issuetime=date("Y-m-d H:i:s");
$sql="insert into userinfo (username,userword,email) values('u2','w2','uw@163.com')";
$result=odbc_exec($connid,$sql);
if($result) echo "successful";
else echo "failed";
?>
3、PHP一般数据读取方法:
<?php //读取mdb数据库例程
$conn=new COM("ADODB.Connection");
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath("../mydata.mdb").";";
//Uid=Admin; Pwd=BDC2002Data;
$conn->open($dsn);
$sql="select * from userinfo";
$rs=$conn->Execute($sql);
$row="0";
while(!$rs->EOF)
{
$string ="";
for ($i=0;$i<$rs->Fields->count;$i++)
{
if ($i==0)
{
$string.=$rs->Fields($i)->Value;
continue;
}
$string.='|'.$rs->Fields($i)->Value;
}
$string.="\n";
if ($row==300)
{
break;
}
$row++;
echo "<br>";
echo $string;
$rs->MoveNext();
}
?>
4、PHP删除数据方法:
<?php
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../mydata.mdb");
$conn->Open($connstr);
$query = "delete from userinfo where uid=1";
$result =$conn->Execute($query);
if($result)
echo "删除成功";
else
echo "删除失败";
?>
5、PHP更新数据方法:
<?php
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../mydata.mdb");
$conn->Open($connstr);
$query = "update userinfo set username='ganjun' where uid=2";
$result =$conn->Execute($query);
if($result)
echo "更新数据成功";
else
echo "更新数据失败";
?>
- 相关文章
- 查看评论:(0)
【已经有0位大神发现了看法】
- [分享]全局标签/条件判断(If Switch Empty),飞飞CMS2.0标签 2013-11-28
- [分享]导航菜单循环标签,飞飞CMS2.0标签 2013-11-28
- [分享]友情链接循环标签,飞飞CMS2.0标签 2013-11-28
- [分享]留言模块调用标签,飞飞CMS2.0标签 2013-11-28
- [分享]评论模块调用标签,飞飞CMS2.0标签 2013-11-28
- [分享]自定义标签使用方法及定义,飞飞CMS2.0标签 2013-11-28
- [分享]视频(内容页/播放页)普通标签,飞飞CMS2.0标签 2013-11-28
- [分享]视频(频道页/栏目页)普通标签,飞飞CMS2.0标签 2013-11-28
- [分享]资讯(万能数据/循环调用)标签,飞飞CMS2.0标签 2013-11-28
- [分享]资讯(频道页/栏目页)共用普通标签,飞飞CMS2.0标签 2013-11-28
发表评论: