Francesco Belladonna
Francesco Belladonna

Reputation: 11689

Import Microsoft Access Database in Mysql database

I have a particular situation where my client require to import (periodically) an ms-access database into his mysql website database (so it's a remote database).

Because the hosting plan is a shared hosting (not a vps), the only way to do it is through PHP through an SQL query, because I don't have ODBC support on hosting.

My current idea is this one (obviusly the client has a MS-Windows O.S.):

I know it's not the best approach so I'm proposing a question to create a different workaround for this problem. The client already said that he wants keep using his ms-access database.

The biggest problem I have is that scripts can last only 30 seconds, which is obviusly a problem to import data.

Upvotes: 1

Views: 1510

Answers (1)

Martin
Martin

Reputation: 6015

To work around the 30-second limit, call your script repeatedly, and keep track of your progress. Here's one rough idea:

if(!file_exists('upload.sql')) exit();

$max = 2000; // the maximum number you want to execute.

if(file_exists('progress.txt')) {
    $progress = file_get_contents('progress.txt');
} else {
    $progress = 0;
}

// load the file into an array, expecting one query per line
$file = file('upload.sql');

foreach($file as $current => $query) {
    if($current < $progress) continue; // skip the ones we've done
    if($current - $progress >= $max) break; // stop before we hit the max
    mysql_query($query);
}

// did we finish the file?
if($current == count($file) - 1) {
    unlink('progress.txt');
    unlink('upload.sql');
} else {
    file_put_contents('progress.txt', $current);
}

Upvotes: 2

Related Questions