0

I'm running WAMP 2.5 with PHP 5.5.12. I'm trying to use odbc_connect to connect to a FoxPro database and eventually query for certain records. But then I realized that dbase is no longer maintained which would of allowed me to access the records for dbf databases. So I tried using ODBC with this code:

<?php
$dsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\wamp\www\chartnames.dbf;Exclusive=NO;collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
$conn = odbc_connect($dsn, "", "");
if (!$conn)
    exit("Connection Failed: " .$conn );

//select rows
$rs = odbc_exec($conn, 'SELECT * FROM chartnames');

//display the results
$string = odbc_result_all($rs); 
?>

But when I run this code I get an error message: enter image description here

If you can't read the error is says this:

Warning:odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Driver does not support this function, SQL state IM001 in SQL Connect

I looked up ODBC on php.net I found that only certain databases are supported by the Unified ODBC functions: Adabas D, IBM DB2, iODBC, Solid, and Sybase SQL Anywhere.

Is it possible to connect and query a .dbf FoxPro table with the new versions of PHP? or

Thank you in advance.

UPDATE: I know that the ODBC driver is no longer supported so they offer OLEDB. I found the OLEDB connection string from here. So I tried replacing the $dsn variable with this connection string: Provider=vfpoledb.1;Data Source=c:\directory\demo.dbc;Collating Sequence=machine but I get the same error as stated above. What gives?

klm10
  • 277
  • 1
  • 12
  • 24
  • That isn't what the error in the image says... It says: `Data source name not found and no default driver specified.` - which means your DSN is wrong. Which of these errors are you currently seeing, and with which connection string? – Sarah Kemp May 20 '14 at 15:46
  • The error messages match now. I need information about the driver not supporting the connect function with this connection string: `$dsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\wamp\www\April\chartnames.dbf;Exclusive=NO;collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";` Thanks. – klm10 May 20 '14 at 15:52
  • You said you couldn't use ODBC, so I would suggest you look closer at the OLE DB DSN. I don't believe you can just put an OLE DB DSN into an `odbc_connect()`. Other questions on this site have resolved by using this COM class - http://stackoverflow.com/questions/2238659/read-foxpro-db-using-php-java?rq=1 http://stackoverflow.com/questions/11247913/connect-to-foxpro-with-php-using-ole-db-driver http://stackoverflow.com/questions/1101338/php-with-oledb – Sarah Kemp May 20 '14 at 17:39
  • I was just researching the COM class as well. Thank you for the useful links. – klm10 May 20 '14 at 17:43

0 Answers0