在Mysql数据库中导入Microsoft Access数据库


Import Microsoft Access Database in Mysql database

我有一个特殊的情况,我的客户需要(定期)将一个ms访问数据库导入到他的mysql网站数据库中(所以这是一个远程数据库)。

因为托管计划是共享托管(而不是vps),所以唯一的方法是通过PHP通过SQL查询,因为我在托管方面不支持ODBC。

我目前的想法是这样的(很明显,客户端有一个MS Windows O.S.):

  • 创建一个小型C#应用程序,将MS Access数据库转换为写在文件上的大型SQL查询
  • 然后,应用程序将使用FTP信息将文件发送到网站上的指定目录
  • 然后,PHP脚本将定期运行(比如每30分钟运行一次),并检查文件是否存在,最终将其导入数据库

我知道这不是最好的方法,所以我提出了一个问题来为这个问题创建一个不同的解决方案。该客户已经表示,他希望继续使用他的ms访问数据库。

我遇到的最大问题是脚本只能持续30秒,这显然是导入数据的问题。

要在30秒左右工作,请反复调用脚本,并跟踪进度。这里有一个粗略的想法:

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);
}