PHP 和 MS 访问 [英] PHP and MS Access

查看:21
本文介绍了PHP 和 MS 访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何将 PHP 脚本连接到 MS Access (.mdb) 文件?

How can we connect a PHP script to MS Access (.mdb) file?

我尝试包含以下 PHP 代码:

I tried by including following PHP code:

$db_path = $_SERVER['DOCUMENT_ROOT'] . 'WebUpdate\' . $file_name . '.mdb';
$cfg_dsn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" . $db_path;
$odbcconnect = odbc_connect($cfg_dsn, '', '');

但它失败了,我收到以下错误消息:

But it failed and I received following error message:

 Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:webWebUpdateindex.php on line 41

推荐答案

这是连接和简单选择的示例...

Here's a sample for a connect and a simple select...

<?php
$db_conn = new COM("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./Northwind.mdb").";";
$db_conn->open($connstr);
$rS = $db_conn->execute("SELECT * FROM Employees");
$f1 =  $rS->Fields(0);
$f2 =  $rS->Fields(1);
while (!$rS->EOF)
{
    print $f1->value." ".$f2->value."<br />
";
    $rS->MoveNext();
}
$rS->Close();
$db_conn->Close();
?> 

这篇关于PHP 和 MS 访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆