Link to home
Start Free TrialLog in
Avatar of scho1178
scho1178

asked on

Update/Delete records in foxpro dbf using PHP

I need to update/delete foxpro dbf files which reside in a linux server by using PHP. dbase functions in PHP dont help. I heard of ODBTP but i not sure how to connect dbf since there are no drivers for linux. Any ideas?

The sample connection code for mssql looks like this
    $odbtpserver = 'odbtpsvr.somewhere.com';
    $mssqldriver = '{SQL Server}';
    $mssqlserver = 'MYMSSQLSERVER';
    $mssqluser   = 'sa';
    $mssqlpass   = '';
    $database    = 'OdbtpTest';

    $connstring  = "DRIVER=$mssqldriver;SERVER=$mssqlserver;UID=$mssqluser;PWD=$mssqlpass;DATABASE=$database;";

   $con = odbtp_connect( $odbtpserver, $connstring ) or die;

but for foxpro dbf  i dont know how.
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

AFAIK, Foxpro uses dbase files (.DBF) so you need to enable the dbase.so extension in php.ini

extension=dbase.so

and then you can use the dbase routines to read and write everything except memo fields.

See http://uk2.php.net/dbase for more information and examples
Here is the code on how to update and delete records.
<?php
//Update a record
// open in read-write mode
$db = dbase_open('/tmp/test.dbf', 2);

if ($db) {
  // gets the old row
  $row = dbase_get_record_with_names($db, 1);
 
  // remove the 'deleted' entry
  unset($row['deleted']);
 
  // Update the date field with the current timestamp
  $row['date'] = date('Ymd');
 
  // Replace the record
  dbase_replace_record($db, $row, 1);
  dbase_close($db);
}

//Delete a Record
// open in read-write mode
$db = dbase_open('/tmp/test.dbf', 2);

if ($db) {
  $record_numbers = dbase_numrecords($db);
  for ($i = 1; $i <= $record_numbers; $i++) {
      dbase_delete_record($db, $i);
  }
  // expunge the database
  dbase_pack($db);
}
//Packs the specified database by permanently deleting all records marked for deletion using dbase_delete_record().
?>
Avatar of scho1178
scho1178

ASKER

Due to a large database is in used, using dbase.so is not suitable for me. What i need is something like ODBC to query the tables.
If you use dbase commands, you will not be using the indexes of VFP and connectivity will be slow.

The option might be to use WINE and install windows MDAC on it. I am not too sure about it though.
I am using Linux OS, hence installing MDAC might not be pratical for me. I feel that ODBTP is suitable for me but i just dunno how to connect to the dbf files in PHP.
I have never used ODBTP. It looks like you will need a windows box for it. Install MDAC and the ODBTP server on it. Either keep the DBF files on the windows server or if you want to keep them on the linux machine, you will need SAMBA and will have to keep them on a shared folder. I would advice on the former. Then you will have to use the ODBTP commands in php to connect to the dbf files.
I am dealing with POS system, frontend is using .dbf database backend is using mysql database. Therefore i need to update 2 different database if there is any new updates, and there is only 1 Linux server.  All programs and databases are kept inside the Linux server. Having an additional windows pc/server will incurred more expenses. That is why i need some tools to access dbf in Linux.
ASKER CERTIFIED SOLUTION
Avatar of tusharkanvinde
tusharkanvinde
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial