php+access 常用代码集锦 实例教程
来源:
互联网
日期:2012-12-24
Tc711Com提示:今天给大家分享:php+access 常用代码集锦 实例教程 ,请大家收藏, 本代码陆续更新中1
|
Access版:
<?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);
Mysql版:
$conn = mysql_connect('localhost','database_user','password');
mysql_select_db('database_to_use',$conn);
$sql = "select/Insert/Delete/Update...";
$rs = mysql_query($sql,$conn);
while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
//这里$row是个关联数组,直接用字段名做key取值
echo $row['字段名1'],'<br />',echo $row['字段名1'];
}
mysql_free_result($rs);
mysql_close($conn);
陆续更新中.... http://bbs.tc711.com/thread-7240-1-1.html
更多的php+access 常用代码集锦 实例教程请到论坛查看: http://BBS.TC711.COM
【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】
来源:
互联网
日期:2012-12-24
|
|
|