How to use multiple database in a PHP web application?
Posted
by Harish
on Stack Overflow
See other posts from Stack Overflow
or by Harish
Published on 2010-04-23T05:20:52Z
Indexed on
2010/04/23
5:23 UTC
Read the original article
Hit count: 248
php
I am making a PHP web Application in which i am using MySQL as database server, i want to make backup of some tables from one database to another database(with that tables in it). i have created two different connection, but the table is not updated.
$dbcon1 = mysql_connect(DB_SERVER,DB_USER,DB_PASSWORD) or die(mysql_error());
$dbase1 = mysql_select_db(TEMP_DB_NAME,$dbcon)or die(mysql_error());
$query1=mysql_query("SELECT * FROM emp");
while($row = mysql_fetch_array($query1, MYSQL_NUM))
{
$dbcon2 = mysql_connect(DB_SERVER,DB_USER,DB_PASSWORD) or die(mysql_error());
$dbase2 = mysql_select_db(TEMP_DB_NAME2,$dbcon)or die(mysql_error());
mysql_query("INSERT INTO backup_emp VALUES(null,'$row[1]',$row[2])");
mysql_close($dbcon2);
}
the code above is taking the data of emp from first database, and updataing it into another backup_emp table of another database. the code is not working properly, is there any other way of doing this...please help.
© Stack Overflow or respective owner