[英]PDO insert from one DB to another
I am trying to use PDO to read a SQLite DB and then insert into MYSQL.我正在尝试使用 PDO 读取 SQLite DB,然后插入 MYSQL。
The read is working and in the foreach I can echo out the SQLite data BUT when it comes to inserting into the new DB nothing logged and no data inserted at all.读取工作正常,在 foreach 中,我可以回显 SQLite 数据,但在插入新数据库时,没有任何记录,也没有插入任何数据。
try
{
$db = new PDO('sqlite:' . $passedFile);
$dbup = new PDO("mysql:host=localhost;port=8889;dbname=TestDB", "dbuser", "password");
//select all lines from the sqlite DB
$result = $db->query('SELECT * FROM TestDB');
foreach($result as $row)
{
$dbup->exec("INSERT INTO TestDB ('field1','field2','field3') VALUES ('" . $row['field1'] . "','" . $row['field2'] . "','" .$row['field3'] . "')");
}
// close the database connection
$db = NULL;
$dbup = NULL;
}
catch(PDOException $e)
{
print 'Exception : '.$e->getMessage();
}
As idea, instead of using $dbup->exec($mysqlQuery)
try $dbup->exec($mysqlQuery) or die(print_r($dbup->errorInfo(), true));
作为想法,不要使用
$dbup->exec($mysqlQuery)
尝试$dbup->exec($mysqlQuery) or die(print_r($dbup->errorInfo(), true));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.