我試圖用php連接dbf數據庫。我嘗試了幾種不同的方式,沒有運氣。Php,odbc&vfp
PHP:5.3.8 文件:C:\ XAMPP \ htdocs中\工作\ vcabdoc.dbf
1RST方式:
創建數據源dbvfp,驅動器C:\ WINDOWS \ SYSTEM32 \ VFPODBC。 dll的
使用$odbc = odbc_connect ('dbvfp', '', '') or die('Could Not Connect to ODBC Database!');
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Visual FoxPro Driver]File c:\xampp\htdocs\work\vcabdoc.dbf is not a database., SQL state S1000 in SQLConnect in C:\xampp\htdocs\WORK\odbc.php on line 5
第二個辦法:
include('\xampp\php\PEAR\adodb\adodb.inc.php');
include_once('\xampp\php\PEAR\adodb\adodb-pager.inc.php');
session_start();
$db = ADONewConnection('vfp');
$dsn="Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\\xampp\\htdocs\\work\\vcabdoc.dbf;Exclusive=No;";
$db->Connect($dsn) or die('nope');
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$query = "Select * from vcabdoc.dbf";
$rs = $db->Execute($query);
echo 'e';
while (!$rs->EOF) {
print_r($rs->fields);
$rs->MoveNext();
Notice: Trying to get property of non-object in C:\xampp\htdocs\WORK\testing.php on line 45
Notice: Trying to get property of non-object in C:\xampp\htdocs\WORK\testing.php on line 46
Fatal error: Call to a member function MoveNext() on a non-object in C:\xampp\htdocs\WORK\testing.php on line 47
第三道:
$conn = new COM("ADODB.Connection");
$conn->Open('Provider=VFPOLEDB.1;Data Source="C:\\xampp\\htdocs\\work\\vcabdoc.dbf;";');
// SQL statement to build recordset.
$rs = $conn->Execute("SELECT * FROM vcabdoc");
echo "<p>List of couriers:</p><hr>";
// Display all the values in the records set
while (!$rs->EOF) {
$fv = $rs->Fields("Name");
echo $fv->value."<br>\n";
$rs->MoveNext();
}
$rs->Close();
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for Visual FoxPro<br/><b>Description:</b> Invalid path or file name.' in C:\xampp\htdocs\WORK\testing.php:54 Stack trace: #0 C:\xampp\htdocs\WORK\testing.php(54): com->Open('Provider=VFPOLE...') #1 {main} thrown in C:\xampp\htdocs\WORK\testing.php on line 54
我這種情況下,試着用和不用雙斜線(\)。
任何幫助?提前致謝。
問候,
若昂
我不太明白你在說什麼,你看,我只有16歲,我試圖爲我的實習做到這一點,如果你可以請更好地向我解釋這一點,在此先感謝和對於我缺乏經驗感到抱歉。 – 2012-03-19 09:34:34
@ user1274469,請參閱修訂答案以進行說明 – DRapp 2012-03-19 11:02:22