- 例一:
- <?php
- //php链接MDB数据库代码示例
- $connstr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath("C:Program FilesAtt2008att2000.mdb");
- $conn = odbc_connect($connstr, "", "", SQL_CUR_USE_ODBC);
- $issuetime = date("Y-m-d H:i:s");
- $sql = "select * from CHECKINOUT where USERID=2";
- $query = odbc_exec($conn, $sql);
- while ($row = odbc_fetch_array($query)) {
- $dt = $row["USERID"];
- $checktime = $row["CHECKTIME"];
- if($checktime < "2011-5-18 13:35:02") {
- echo $checktime;
- }
- }
- ?>
- 例二:
- <?php
- /***
- This file is just for an example of Php+Access.
- You can find these functions from http://www.php100.com/cover/php/1681.html
- */
- /* ODBC string */
- $odbc = "Driver={Microsoft Access Driver (*.mdb)};Dbq=".realpath("our.mdb");
- $conn = odbc_connect($odbc, '', '', SQL_CUR_USE_ODBC);
- $sql ="select * from test";
- $query = odbc_exec($conn, $sql);
- print $query."</br>";
- $num = odbc_num_fields($query);
- if ($num != 0)
- for($i=1; $i<$num; $i++)
- {
- $row = odbc_fetch_row($query);
- echo "->".odbc_result($query,"Addr")."</br>";
- //echo "->".odbc_result($query,3)."</br>"; /* the same as Line 24*/
- }
- else
- print "No data";
- ?>
- 例三:
<?php
//create link
$conn = @new com('ADODB.Connection') or die('ADO Connection failed.');
$connstr = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source='.$_SERVER['DOCUMENT_ROOT'].'FILENAME.mdb';
$conn->Open($connstr);
echo 'linked successful';
//create search
$rs = @new com("ADODB.RecordSet");
$rs->Open("select * from TABLENAME",$conn);
//read data
while(!$rs->eof)
{
echo $rs->Fields['LISTNAME']->Value.'<br>';
$rs->Movenext();
}
$rs->close();
?>
例四:
try{
$path2="D:/myenv/Apache24/htdocs/www/xiongmaoxueyuan/xiongmaoxueyuan.accdb";
$db = new PDO("odbc:driver={microsoft access driver ( *.accdb)};dbq=".$path2);
echo "Connected success ";
} catch (Exception $e) {
echo "Failed:".iconv('GB2312', 'UTF-8', $e->getMessage());
}
$rs = $db->query('select * from test');
print "<pre>";
print_r($rs->fetchAll());
print "</pre>";
例五:
-
<?
-
$conn = new com("ADODB.Connection");
-
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("data/db.mdb");
-
$conn->Open($connstr);
-
$rs = new com("ADODB.RecordSet");
-
$rs->Open("select * from szd_t",$conn,1,1);
-
while(! $rs->eof) {
-
$f = $rs->Fields(1);
-
echo $f->value;
-
$rs->MoveNext();
-
}
?>
例六:
提供已知的几种连接方式: 1. $conn = new com("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("test.mdb"); $conn->Open($connstr); 2. $conn=new com("ADODB.connection"); $connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".realpath("test.mdb"); $conn->open($connstr); 3. $connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);
在ThinkPhp的controller中由于存在命名空间,所以要使用“$conn = new com("ADODB.Connection");”
http://zhidao.baidu.com/question/383674258.html?qbl=relate_question_1&word=php%20mdb
$rs=new com('adodb.recordset');$rs->Open('SELECT * FROM 数据表名',$conn,1,1);
$rs->PageSize=50;
$page=1;
if(!empty($_GET['page'])){
$page=$_GET['page'];
if($page<1)$page=1;
if($page>$rs->PageCount)$page=$rs->PageCount;
}
$rs->AbsolutePage=$page;
echo '<table width="100%"><tr>';
foreach( $rs->Fields as $name){
echo '<td>'.$name->Name.'</td>';
}
echo '</tr>';
for(;!$rs->EOF;$rs->MoveNext()){
echo '<tr>';
foreach( $rs->Fields as $name){
echo '<td>'.$name.'</td>';
}
echo '</tr>';
if($rs->AbsolutePosition>=$rs->AbsolutePage*$rs->PageSize)break;
}
echo '</tale>';
for($i=0;$i<$rs->PageCount;$i++){
echo '<a href="index.php?page='.($i+1).'"> '.($i+1).' </a>';
}