Home > php教程 > php手册 > pdo连接access数据库代码

pdo连接access数据库代码

WBOY
Release: 2016-06-13 10:07:47
Original
799 people have browsed it

pdo连接access数据库教程代码
//php教程.ini需要开放:
//extension=php_pdo.dll
//extension=php_pdo_odbc.dll
//数据库为acc.mdb,为防止恶意下载,改为acc.php

try{
    $db = new pdo("odbc:driver={microsoft access driver (*.mdb)};dbq=".getcwd()."\acc.php",'aaa','123456'); //getcwd()函数是获取当前路径
    //echo "connectedn";

 date_default_timezone_set('asia/shanghai'); //北京时间
  $v="测试".date("y-m-d h:i:s")."添加的内容";
  $db->exec("insert into table1(topic) values('$v')");//插入
  //echo $db->lastinsertid(); //不支持
  $rs=$db->query("select * from table1"); //选择
  while($row=$rs->fetch()){
  echo $row[id]."-".$row[topic]."
";
  };

   } catch (exception $e) {
     //echo "failed:".$e->getmessage();
   }

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template