gpt4 book ai didi

php - 如何从access导入特定行到mysql?

转载 作者:行者123 更新时间:2023-11-30 01:37:55 25 4
gpt4 key购买 nike

是否有任何解决方案可以将某些行从 Access 导入到 MySQL?或不?谁能给我一个在 MySQL 中执行的查询,以将主表中的某一行导入到另一个表中?

最佳答案

有可能,您需要连接到两个数据库,例如使用 PDO。下面我假设你现在有Access和MySQL的表结构。

$access = new PDO( ... ); // insert your MS Access DSN, perhaps via ODBC
$mysql = new PDO(...); // the same with MySQL

// you need to check here if connections were successful

$query_acc = $access->query('SELECT * FROM AccessTableName');

$query_mysql = $mysql->prepare('INSERT INTO MySQLTableName VALUES(%val1, %val2, %val3 ...)');

while($row = $query_acc->fetchAll()){ // choose the method you like most
$query_mysql->bindValue('%val1', $row['val1']);
// do the same with other fields
// ...
$query_mysql->execute();
}

也许代码可以优化,但正如您所看到的,它非常简单。

关于php - 如何从access导入特定行到mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16603068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com