Home > Backend Development > PHP Tutorial > PHP连接Access数据库的方法小结_PHP

PHP连接Access数据库的方法小结_PHP

WBOY
Release: 2016-06-01 12:06:14
Original
912 people have browsed it

PHP代码:

需要注意php获取路径用的是realpath
复制代码 代码如下:
$connstr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("data.mdb");
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC);
$issuetime=date("Y-m-d H:i:s");
$sql="insert into test values("","",...)";
$result=odbc_exec($connid,$sql);
if($result) echo "successful";
else echo "failed";
?>


之二:

复制代码 代码如下:
//创建ADO连接
$conn = @new COM("ADODB.Connection") or die ("ADO连接失败!");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("temp/TempData.mdb");
$conn->Open($connstr);

//创建记录集查询
$rs = @new COM("ADODB.RecordSet");
$rs->Open("select * from blog_Content",$conn,1,3);
echo $rs->Fields["log_Title"]->Value; //输出log_Title字段
echo "
";
$rs->Movenext(); //将记录集指针下移
echo $rs->Fields["log_Title"]->Value;
$rs->close();
?>


方法三:用ODBC,在ODBC治理器中为db1.mdb建一处系统数据源(一般需要服务器权限,不建议使用)

名称:dbdsn (可以自己定)
驱动程序:Microsoft Access Driver (*.MDB)

代码:
复制代码 代码如下:
$Conn = odbc_connect("dbdsn","admin","123"); //连接数据源
$Doquery=odbc_exec($Conn,"select * from 表名 where 条件");//执行查询


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template