DBF is very old format databse type. About 10 years ago, I use dBase which use DBF format.
Now I will show you how to connect the DBF file from PHP script.
1) Add a system DSN in ODBC Data Source Administrator
I have a source named dd.

2) Make a file named odbc.php, the content is:
<?php
$odbc = odbc_connect ('dd', '', '') or die('Could Not Connect to ODBC Database!');
?>
3) In the PHP file, which needs to connect this database, I use the following script.
$strsql= 'SELECT * FROM database.dbf';
$query = odbc_exec($odbc, $strsql) or die (odbc_errormsg());
while($row = odbc_fetch_array($query))
{
echo 'Client Name: '.$row['name'].'<br />';
echo 'Client Phone Number: '.$row['phone'].'<br />';
echo '<hr />';
}
odbc_close($odbc);
Use this way, PHP can connect the old database file, like dBase, Foxpro.



Hi David.
I am trying to connect to a .dbf file via php.
I tried your to follow your instructions.
1. Created a "dd" connection via my ODBC admin
2. Created both .php files
3. Created a small dbf file with three name/phone records.
When I run the main php script, I receive the following error message:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][Pilote ODBC dBase] Syntax error in clause FROM., SQL state 37000 in SQLExecDirect in c:\Web\essai\testdbase.php on line 5
[Microsoft][Pilote ODBC dBase] Syntax error in FROM clause.
The files are currently on my test server. You can test them at:
http://www.pconno.gotdns.com/essai/testdbase.php
Seems that:
1. The connection works fine (I receive no "die" )message
2. The dbase file is found ok
3. The querry string is somehow defective.
Would you have any suggestion?
Thanks a lot,
Pierre
I have get back to you by email. I think it should be OK now.
Dear David,
where are your databases (dbf)? I don't know that where should i put it?
Pls advise me.
Many thanks,
Jack
The dbf files are saved in any folder. Say, I have three dbf files in c:\data-dbf\.
When I add system DSN and select Microsoft dBase drive, it will let me choose the folder.
Any dbf file in this folder can be accessed by this way.