PDO insert from one DB to another
I am trying to use PDO to read a SQLite DB and then insert into 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.
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));
精彩评论