ADO是一项微软的技术,ADO指ActiveX数据对象(ActiveX Data Objects).
链接数据库
<?php header("Content-Type:text/html; charset=utf-8"); $dsn="DRIVER=Microsoft Access Driver (*.mdb);DBQ=".realpath("test.mdb"); $conn=odbc_connect($dsn,"","",SQL_CUR_USE_ODBC );
执行插入操作
$query=odbc_do($conn,"select * from tb_user");
循环输出
$i=1; while(odbc_fetch_row($query)){ //转码(防止乱码) echo "第".$i."条记录!"; echo "<br/>"; echo "编号:".iconv('gb2312','utf-8',odbc_result($query,1)); echo "<br/>"; echo "姓名:".iconv('gb2312','utf-8',odbc_result($query,2)); echo "<br/>"; echo "电话:".iconv('gb2312','utf-8',odbc_result($query,3)); echo "<br/>"; echo "<hr/>"; $i++; } if($i<2){ echo "对不起,数据表为空! "; }
插入(insert)
//为防止中文插入乱码,进行编码转换 $name=iconv('utf-8','gb2312//IGNORE',"测试");$sql="insert into tb_user(name,phone)values('{$name}','100861')"; //执行插入操作; $re=odbc_do($conn, $sql);if($re){ echo "恭喜你,插入成功!";}else{ echo "对不起,插入失败!";}
修改(update)
//转换编码,拼接sql语句; $name=iconv('utf-8','gb2312//IGNORE',"修改后值:上线");$sql="update tb_user set name='{$name}'where id=55"; //执行,并判断执行结果; $re=odbc_exec($conn, $sql);if($re){ echo "恭喜你,修改成功!";}else{ echo "对不起,修改失败!";}
删除(delete)
//删除sql $sql="delete from tb_user where id=55"; /执行 $re=odbc_exec($conn, $sql);if($re){ echo "恭喜你,删除成功!";}else{ echo "对不起,删除失败!";}