E生相爱工作室

18778998308服务热线

好管家网络

PHP+ACCESS 实例

作者: 发表时间:2013/8/16 11:01:39浏览量:1003

$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一般数据写入方法:

$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一般数据读取方法:

$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 "
";
   echo $string;
   $rs->MoveNext();

}

?>

4、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更新数据方法:

$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   "更新数据失败";  
   
?> 
 



TAG:网站建设,网站推广,微信公众号开发、小程序开发、网站活动策划,H5制作,代运营,网站代运营,微信代运营,公众号代运营,网站定制,代维护
2013/8/16 11:01:39 1003浏览