aiiwa
aiiwa

Reputation: 611

Unable to read visual foxpro dbf table using PHP (ole db)

I am trying to read visual foxpro .dbf files using php and getting the following error:

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\phpdbf\index.php:41 Stack trace: #0 C:\xampp\htdocs\phpdbf\index.php(41): com->Open('Provider=VFPOLE...') #1 {main} thrown in C:\xampp\htdocs\phpdbf\index.php on line 2

I have downloaded and run provider from here (note: not sure if I need to do any extra configuration - just simply run it).

Here is my code: (note: I am not sure about the "ADODB.Connection" and "Provider=VFPOLEDB.1" values in the code. let me know if they don't stand for defaults)

$conn = new COM("ADODB.Connection");
$conn->Open('Provider=VFPOLEDB.1;Data Source="C:\\xampp\\htdocs\\phpdbf;";');

//test.dbf is the file
$rs = $conn->Execute("SELECT * FROM test");

// Display all the values in the records set
while (!$rs->EOF) { 
    $fv = $rs->Fields("my_datetime");
    echo $fv->value."<br/>";
    $rs->MoveNext();
} 
$rs->Close(); 

Note: I have tried the answer here , but still getting this error.

Upvotes: 3

Views: 2071

Answers (1)

Caltor
Caltor

Reputation: 2766

Your data source needs to point at the visual Foxpro .dbc file. Example

Data Source="c:\\vfpdata\\mydatabase.dbc"

Upvotes: 1

Related Questions