473,385 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using conection from two different data bases in same php file

190 100+
can i make use of two different connection using different database in a same php file , if yes , then how
Jan 22 '08 #1
3 1112
code green
1,726 Expert 1GB
Just make sure you keep seperare copies of the Resource link Identifier for each connection
Expand|Select|Wrap|Line Numbers
  1. $db1 = mysql_connect........
  2. $db2 = mysql_connect........
And always use the identifiers for every query etc
Jan 22 '08 #2
can 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"=>"localhost",
"Username"=>"root",
"Password"=>"",
"Database"=>"DB1",
);
$DB_HOST2=array(
"Host"=>"host name or IP",
"Username"=>"abc",
"Password"=>"abc",
"Database"=>"DB2",
);

suppose first is MYSQL

$conn1=mysql_pconnect($DB_HOST1[Host"], $DB_HOST1[["Username"], $DB_HOST1["Password"]);mysql_select_db($DB_HOST1[["Database"],$conn1);

and second is oracle then

strConn="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST = $DB_HOST2["Host"])
(PORT=1521)
)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=$DB_HOST2["Database"])
)
)

then connect
$conn2=OCIPLogon(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("sql statement",connection 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 Agrawal
Jan 22 '08 #3
Shalini Bhalla
190 100+
Thanks a lot sir for ur help ....
Jan 26 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
0
by: Glich via DotNetMonster.com | last post by:
#using <mscorlib.dll> #using <System.dll> #include "stdlib.h" #include "stdio.h" using namespace System; using namespace System::Text; using namespace System::IO; using namespace...
0
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.