如果要用PHP 連到 access 最好的方法就是 下載使用ADODB來進行配接比較方便

只要先安裝ADODB 然後將 adodb.inc.php 叫進來就可以了

 

PS: 要先設定好ODBC,

access資料庫連接方法:

ODBC設定於『控制台』→『系統管理工具』

教學網址: http://academic.ntou.edu.tw/system/setodbc.asp

以下是php 連上 access 的程式

------------------------------------------------------------------------------------------------------------------------------------------------------------

include('adodb/adodb.inc.php');
$conn = &ADONewConnection('access');    # 建立一個連結
$conn->PConnect('borad');   # 連結到 MS-Access borad資料庫

$recordSet = &$conn->Execute('select * from admin');
if (!$recordSet)
        print $conn->ErrorMsg();
else
while (!$recordSet->EOF) {
        print 'id:'.$recordSet->fields[1].' pwd:'.$recordSet->fields[2].'<BR>';
        $recordSet->MoveNext();
}

$recordSet->Close(); # 選擇性執行
$conn->Close(); # 選擇性執行

新增的程式碼:

$insertSQL="insert into admin(username,passwd,name,rights) values('halladay','1234','jue','0')";
$conn->Execute($insertSQL); # 將記錄挿入資料庫中 

 

 

------------------------------------------------------------------------------------------------------------------------------------------------------------

 

參考:

下載點: http://www.csie.nctu.edu.tw/~tsaiwn/course/introcs/history/linux/linux.tnc.edu.tw/techdoc/adodb/c46.html

教學:

http://www.csie.nctu.edu.tw/~tsaiwn/course/introcs/history/linux/linux.tnc.edu.tw/techdoc/adodb/book1.html

http://www.php5.idv.tw/documents/ADODB/#ex7

------------------------------------------------------------------------------------------------------------------------------------------------------------

ODBC設定

ODBC連線設定教學
ODBC設定於『控制台』→『系統管理工具』
選擇系統資料來源名稱後按下新增
資料來源選擇SQL Server後按下完成
 

名稱請輸入student

描述可空白

伺服器請輸入dbserver

點選『由使用者所輸入的登入識別碼及密碼進行SQL Server帳戶驗證』後按下『用戶端設定』

按照圖示操作

伺服器名稱請輸入『db.ntou.edu.tw』

輸入登入識別碼及密碼

登入識別碼為『aascrt』密碼若忘記請洽課務組或電算中心

直接下一步
請取消『為字元資料執行轉譯』
請測試連線
恭喜你,當看到『成功的完成測試』便是您的ODBC設定完成了
 

 

 
arrow
arrow
    全站熱搜

    halladay5364 發表在 痞客邦 留言(0) 人氣()