mysql - Insert row from one table to another table, which has extra column? -


i working on migration of data 1 db1 db2.

i have 1 scenario, table person present in both databases(db1 , db2).

but table in db2 has 1 column. best effective way write query migrate data db1 person db2 person.

i have written below, best way write it? because if have more columns , 1 column, due need mention column names in loop statement.

$select = $dbh1->prepare("select * person"); $insert = $dbh2->prepare("insert person values (?,?,?,?,?)");  $select->execute;  while ( my($pr_id,$name,$lastname) = $select->fetchrow_array ) {   $insert->execute($pr_id,$name,$lastname,'null','null'); } 

if there column mismatch in source , target table use syntax per below-

insert table1(col1,col2,col3) select col1,col2,col3 table2; 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -