PHP访问ACCESS数据库的两种方法

PHP访问ACCESS的两种方法:
ADODB方式
<?PHP
$conn = new COM("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath
("D://data//ip.mdb");
$conn->Open($connstr);
$rs = new COM("ADODB.RecordSet");
$rs->Open("select ip from ip",$conn,1,1);
while(! $rs->eof)

  $f = $rs->Fields(1);
  echo $f->value;
  $rs->MoveNext();
}
?>

ODBC 方式
<?PHP
$dsn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("D://data//ip.mdb");
$conn = odbc_connect($dsn,"","") or die("error");
$sqlquery = "select * from acgroup";
$exec = odbc_exec($conn,$sqlquery);
while($row = odbc_fetch_array($exec))
{
$ip=$row['GroupID'];
echo $ip;
echo "/r/n";
}
?>

 

 

你可能感兴趣的:(PHP访问ACCESS数据库的两种方法)