=波波日志 > PHP/apache/Perl > php在window下连接和使用access数据库=
php在window下连接和使用access数据库
示例代码点击这里下载
连接acc数据库
使用游标属性eof,bof及fields
用游标更新数据库,addnew,update方法
使用连接对象的execute方法
连接acc数据库
+展开
-PHP
$cnStr="provider=microsoft.jet.oledb.4.0;data source=".realpath("db.mdb");
$cn;
function OpenDB()
{
global $cn,$cnStr;
$cn=new COM("adodb.connection");
$cn->open($cnStr);
}
function CloseDB()
{
global $cn;
$cn->close();
$cn=null;
}
$cn;
function OpenDB()
{
global $cn,$cnStr;
$cn=new COM("adodb.connection");
$cn->open($cnStr);
}
function CloseDB()
{
global $cn;
$cn->close();
$cn=null;
}
使用游标属性eof,bof及fields
+展开
-PHP
$result=false;
$rs=$cn->execute("select id from [user] where username='".str_replace("'","''",$name)."'");
if($rs->eof ||$rs->bof||(int)$rs->fields[0].value==(int)$id)$result=true;
//和asp的游标差不多,也可以使用 $rs[0]这样来获取,注意asp是rs(0)
$rs->close();$rs=null;
return $result;
$rs=$cn->execute("select id from [user] where username='".str_replace("'","''",$name)."'");
if($rs->eof ||$rs->bof||(int)$rs->fields[0].value==(int)$id)$result=true;
//和asp的游标差不多,也可以使用 $rs[0]这样来获取,注意asp是rs(0)
$rs->close();$rs=null;
return $result;
用游标更新数据库,addnew,update方法
+展开
-PHP
$sql="select * from [user] where 1=2";
if($ac=="up")$sql.=" or id=".$id;
$rs=new COM("adodb.recordset");
OpenDB();
if(!CKNameExist($cn,$un,$id)){//检查用户名是否已经存在
echo "<script>alert('该用户名已经存在,请另外输入新的用户名!');history.back();</script>";
CloseDB();
die();
}
$rs->open($sql,$cn,1,3,1);
if($ac=="add")$rs->AddNew();
elseif($rs->eof || $rs->bof){
$rs->close();$rs=null;CloseDB();
echo "<script>alert('该用户信息不存在!');history.back();</script>";
die();
}
$rs[1]=$un;
$rs[2]=$pw;
$rs->Update();
$rs->close();$rs=null;
CloseDB();
if($ac=="up")$sql.=" or id=".$id;
$rs=new COM("adodb.recordset");
OpenDB();
if(!CKNameExist($cn,$un,$id)){//检查用户名是否已经存在
echo "<script>alert('该用户名已经存在,请另外输入新的用户名!');history.back();</script>";
CloseDB();
die();
}
$rs->open($sql,$cn,1,3,1);
if($ac=="add")$rs->AddNew();
elseif($rs->eof || $rs->bof){
$rs->close();$rs=null;CloseDB();
echo "<script>alert('该用户信息不存在!');history.back();</script>";
die();
}
$rs[1]=$un;
$rs[2]=$pw;
$rs->Update();
$rs->close();$rs=null;
CloseDB();
使用连接对象的execute方法
+展开
-PHP
OpenDB();
$cn->execute("delete from [user] where id=".$id);
CloseDB();
$cn->execute("delete from [user] where id=".$id);
CloseDB();
类别:PHP/apache/Perl 作者:波波 日期:2009-07-10 【评论:0】
暂时没有评论!
发表留言
百度赞助
同类热门博文
- ·IE里Cookie跨域不能..
- ·php隐形字符65279
- ·Apache NameVirtual..
- ·Apache2.2提示Canno..
- ·Cookie在IE浏览器跨..
- ·获取google的pr值
- ·php根据访问者ip地址..
- ·PHP“Cannot use ob..
博格Tag
- flash/flex/fcs/AIR(752)
- Asp.Net/C#/WCF(598)
- 操作系统及应用软件(376)
- JavaScript/Ajax(330)
- SQL及数据库(134)
- 黑客技术(115)
- Asp/VBScript(111)
- HTML/WML/CSS兼容/XML(102)
- PHP/apache/Perl(96)
- 网站排名及优化(92)
- 其他(75)
- showbo日志(66)
- lucene.net/分词技术(33)
- 计算机网络(26)
- 机械重工(26)
- C#设计模式(24)
- Google Maps开发(17)
- 日语学习(15)
- Canvas/VML/SVG(13)
- linux(11)
- 游戏开发(8)
- 正则表达式(5)
- Jsp/Java(4)
最新博文
- ·PHP socket套接字学..
- ·Warning Cannot sen..
- ·php与flash as3 soc..
- ·php socket套接字聊..
- ·php获取来源页面
- ·CentOS5.5配置Apach..
- ·wget使用详解
- ·curl使用详解
随机博文
