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.
scho1178Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Beverley PortlockCommented:
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
0
cyrusjoudiehCommented:
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().
?>
0
scho1178Author Commented:
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.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

tusharkanvindeCommented:
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.
0
scho1178Author Commented:
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.
0
tusharkanvindeCommented:
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.
0
scho1178Author Commented:
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.
0
tusharkanvindeCommented:
Your solution might be installing WINE and then MDAC on top of it. give a visit to  http://www.winehq.org/ and see if you can find anything. If you do succeed, let me know.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.