Insert data into two tables of different databases on same instance

If both databases reside on the SAME MySQL server (and use the same user and password to connect). You simply establish the connection without picking a database, then put the name of the database in front of the table name like:

INSERT INTO myDBname.myTableName (myKey) VALUES (myValue);

If you have a connection to one database you can change it before inserting:

$pdoConnetion->select_db('myDBName');
INSERT INTO myTableName (myKey) VALUES (myValue);

Comments are closed.