I've never done this with PHP, but I did make a Perl script that would do it for me.
#!/usr/bin/perl
Program to load .DBF files into MySQL
use DBI;
use XBase;
Load .DBF files into MySQL
$database = "database";
$user = "user";
$password = "password";
#$dbfpath = the directory of the .DBF files
$dbfpath = "/web/globaldominion.net/data";
Connect To MySQL
$driver = "mysql";
$dsn = "DBI:$driver:database=$database";
$mysqldbh = DBI->connect($dsn, $user, $password);
Connect to DBF "database"
$dbfdbh = DBI->connect("DBI:XBase:$dbfpath") or die $DBI::errstr;
Gather information from DBF files
table is the name of the .DBF file without the .DBF extention
$file1 = $dbfdbh->prepare(q{SELECT * FROM table}) or die $dbfdbh->errstr();
$file1->execute() or die $file1->errstr();
Load DBF data for file1
my $query = "DELETE FROM mysql_table"; #just clearing out the table if needed
$mysqldbh->do($query) or die $mysqldbh->errstr();
#quick fix for "
while (@dbf_table_rows = $file1->fetchrow()) {
for ($i = 0; $i <= 15; $i++) {
$dbf_table_rows[$i] =~ s/"/'/g;
}
#use a sprintf to format the SQL query for inserting into the MySQL table
my $query = sprintf(q{INSERT INTO mysql_table VALUES (
"%s", "%s", "%s", %d, "%s", %d, "%s",
"%s", %d, "%s", "%s", "%s", "%s", %d,
"%s")}, @dbf_table_rows);
$mysqldbh->do($query) or die print "$query\n";
}