代码之家  ›  专栏  ›  技术社区  ›  ircmaxell

批量插入和准备的查询错误

  •  3
  • ircmaxell  · 技术社区  · 15 年前

    好的,我需要用MySQL查询的结果填充msaccess数据库表。这一点也不难。我已经把程序写在那里,它将template.mdb文件复制到一个临时名称,并通过odbc打开它。到目前为止没问题。

    我注意到Access不支持批插入( VALUES (foo, bar), (second, query), (third query) ). 因此,这意味着我需要每行执行一个查询(可能有数十万行)。最初的性能测试显示,访问速度大约为900次插入/秒。对于我们最大的数据集,这可能意味着执行时间为分钟(这不是世界末日,但显然越快越好)。

    所以,我试着测试一份准备好的声明。但我总是出错( Warning: odbc_execute() [function.odbc-execute]: SQL error: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect , SQL state 07001 in SQLExecute in D:\....php on line 30

    odbc_execute ):

    $sql = 'INSERT INTO table 
        ([field0], [field1], [field2], [field3], [field4], [field5]) 
        VALUES (?, ?, ?, ?, ?, ?)';
    $stmt = odbc_prepare($conn, $sql);
    for ($i = 200001; $i < 300001; $i++) {
        $a = array($i, "Field1 $", "Field2 $i", "Field3 $i", "Field4 $i", $i);
        odbc_execute($stmt, $a);
    }
    

    ? 标记)?第二,我是否应该费心处理这个问题,或者直接使用INSERT语句?正如我所说,时间并不重要,但如果可能的话,我希望时间尽可能少(同样,我可能会受到磁盘吞吐量的限制,因为900次操作/秒已经很高了)。。。

    谢谢

    2 回复  |  直到 15 年前
        1
  •  1
  •   Community Mohan Dere    8 年前

    你需要一排一排地做这个吗?为什么不一次插入所有的数据呢?

    What is the best way to synchronize data between MS Access and MySQL?

        2
  •  1
  •   HansUp    15 年前

    另外,我不知道PHP,但是数组的第二个成员应该是“Field1$I”而不是“Field1$”?

    INSERT INTO table 
        ([field0], [field1], [field2], [field3], [field4], [field5]) 
    VALUES (
        200001,
        'Field1 200001',
        'Field2 200001',
        'Field3 200001',
        'Field4 200001',
        200001);
    

    $sql = 'INSERT INTO table 
        ([field0], [field1], [field2], [field3], [field4], [field5]) 
        VALUES (?, "?", "?", "?", "?", ?)';
    
    推荐文章