can i make use of two different connection using different database in a same php file , if yes , then how
Using conection from two different data bases in same php file
Collapse
X
-
Tags: None
-
Just make sure you keep seperare copies of the Resource link Identifier for each connectionAnd always use the identifiers for every query etcCode:$db1 = mysql_connect........ $db2 = mysql_connect........
-
Originally posted by Shalini Bhallacan i make use of two different connection using different database in a same php file , if yes , then how
Hi Shalini,
you can make different connection using different database.
first make the two object of the database .
For example two DB
$DB_HOST1=array (
"Host"=>"localh ost",
"Username"=>"ro ot",
"Password"= >"",
"Database"=>"DB 1",
);
$DB_HOST2=array (
"Host"=>"ho st name or IP",
"Username"=>"ab c",
"Password"=>"ab c",
"Database"=>"DB 2",
);
suppose first is MYSQL
$conn1=mysql_pc onnect($DB_HOST 1[Host"], $DB_HOST1[["Username"], $DB_HOST1["Password"]);mysql_select_db ($DB_HOST1[["Database"],$conn1);
and second is oracle then
strConn="(DESCR IPTION=(ADDRESS =(PROTOCOL=TCP)
(HOST = $DB_HOST2["Host"])
(PORT=1521)
)
(CONNECT_DATA=
(SERVER=DEDICAT ED)
(SERVICE_NAME=$ DB_HOST2["Database"])
)
)
then connect
$conn2=OCIPLogo n(DB_HOST2["Username"], DB_HOST2["Password"], $strConn);
Now u have two connection so u can use two databess who is required.
use the object of database in MYSQL_QUERY("sq l statement",conn ection id object); in case of mysql
but better way to make a class and two different function of different database so when u required other DB them called the class and call a diifferent DB call
Regards,
Sandeep AgrawalComment
-
Comment