Wednesday 14 September 2011

How to copy one table content from one database to another database using PHP


This is a simple problem faced by me to get required objective. After hours of googling i come up with some code to achieve my task.
Let's two databases and two corresponding tables, db1.tbl1 and db2.tbl2.

$query=db_query("SELECT * FROM db1.tbl1");
while($row=db_fetch_object($query))
{
$row1=$row->row1;
$row2=$row->row2;
$time=time();
$insert_query=db_query("insert into db2.tbl2 (field1,field2,time) VALUES ('%d','%s','%d')",$row1,$row2,$time);
   }

More information on www.narendrarathore.com

No comments:

Post a Comment