dbf file

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nikanj
Forum Newbie
Posts: 2
Joined: Mon Jun 19, 2006 6:51 pm

dbf file

Post by nikanj »

I've got a .dbf file (foxpro, I believe) that I would like to read. The file is part of another application that updates it once in a while, ie: it is not static, it gets changed and must be read every other day or so.

I want to be able to open the file and import it to a mysql database, updating the mysql table on a regular basis.

The problem: I tried the following code

Code: Select all

$id = @dbase_open("contacts.dbf", 0)
   or die ("Could not open dbf file."); 
   
$record = dbase_get_record($id, 955);
But, I get the error (as you might expect) "Could not open dbf file." I've tried using PHP to create and then read a test dbf file and that works fine, so I think there is a problem with the file. The file is in the proper location and is accessible (it's in the same folder as the test dbf file.)

The program DBFview shows me this info about the file:

Code: Select all

C:\www\contacts\contacts.dbf
 File size (bytes): 1793394
 Version: FoxPro with memo, index present
 Number of records: 9640

   N  Field name    Type     Width
 ---------------------------------
   1  ID         Numeric      10
   2  LINKID     Numeric      10
   3  FNAME      Character    24
   4  LNAME      Character    24
   5  COMPANY    Character    48
   6  COMPID     Character     8
   7  OCUPATION  Character    16
   8  POSITION   Character    16
   9  LASTUPDATE Float        19.9
  10  TEXTBLOB   Memo         10
 ---------------------------------
 Total:                      186
I noticed another post on this forum that talked about the wrong version of dbf file and I'm hoping that this is not the case for me. Other than contacting the developer is there anyway to find out? Does anybody have any other suggestions?

BTW: I can't just use something like dbfviewer to produce the sql to insert it into a mysql table, because the file is "live" being changed daily by another application.

BBTW: the contacts.dbf file I'm testing on, is NOT live -- it has been copied to another directory so I can play with it, without damaging the original.

My Setup:
Apache2
PHP5 (with php_dbase.dll)
win xp

I'm thinking, perhaps there might be a way to treat this as a flat text file that I can extract rows from. Not sure, I'll have to play with it.

If I left anything out, ask me..... and thanks in advance.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: dbf file

Post by Christopher »

Given the error message you might want to try something like:

Code: Select all

$id = @dbase_open('C:/www/contacts/contacts.dbf', 0)
   or die ("Could not open dbf file."); 
   
$record = dbase_get_record($id, 955);
(#10850)
nikanj
Forum Newbie
Posts: 2
Joined: Mon Jun 19, 2006 6:51 pm

Re: dbf file

Post by nikanj »

Thanks. I just tried that and still, the same problem.

I tried this, on another file that's right next to contacts.dbf and it works.

Code: Select all

<?php 

$id = @dbase_open('C:/www/contacts/dbfile_test.dbf', 0)
   or die ("Could not open dbf file.");
   
$record = dbase_get_record($id, 1);
?>
Any suggestions on how I might get something in the die that will give me a more descriptive error. Something perhaps equivalent to mysql_error()?

I'm experimenting with ODBC, but not having much luck... since I've only got a .dbf file available. ODBC seems to want a .dbc file.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You might want to get a dbf file viewer and see if the contact file is corrupted or so unsupported version. You might be able to get a text export out of the file at minimum if it's not corrupted.
(#10850)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

arborint wrote:You might want to get a dbf file viewer and see if the contact file is corrupted or so unsupported version. You might be able to get a text export out of the file at minimum if it's not corrupted.
I was looking for a dbf editor in an earlier thread and found that the reason I could not work with the file is because it uses the dbf extension, but it is was proprietary to MIVAsql (I'm not saying that is the case for you, but here is the thread).

viewtopic.php?t=48841&highlight=dbf

There are a bunch of editors referenced in there.
Post Reply