Hi everyone,
I want to connect two different database server using php/mysql.
Suppose i have some dat on www.xyz.com and i want to select that data on www.abc.com
How do i integrate two different database server please some body tell me...
Thanks in advance
24 24764
do you know how to connect to one database? if not look online for PHP tutorial and read the manual at php.org
I don't even know what database you're using, if MySQL then php has native functions for that.
If you know how to connect to one, then you can connect to multiple.
Dan
of course i know how to connect one database but i am facing the problem like if i connect two different databse on local server it works fike and when i upload that file to remote server its not working and i am using PHP 5.0/MYSQL .
to work with a remote server you usually need permissions to access it (many ISP servers allow only localhost access). otherwise you need to make sure to always pass the correct resource link. (if you're using PDO you might get away with 2 DB objects, though)
i am connecting two database server with this code. -
For first server
-
<?php
-
$hostname = "hostname";
-
$username = "username";
-
$password = "password";
-
$con = mysql_connect($hostname,$username,$password) or die("Database not connected");
-
mysql_select_db("database");
-
?>
-
-
For second server
-
<?php
-
$hostname = "hostname1";
-
$username = "username1";
-
$password = "password1";
-
$con = mysql_connect($hostname,$username,$password) or die("Database not connected");
-
mysql_select_db("database1");
-
?>
-
@tokcy
this code will probably get you in trouble if you want to use both connections in the same script.
- the second connection will overwrite the first one (you need to use different variable names)
- if you're using more than one connection, you must (in a logical sense) pass the connection resource to every mysql_* function.
my personal recommendation: use PDO. it boils down to using 2 different DB objects, which is IMO easier to track and maintain (beside the various other advantages that come with PDO (Exceptions, Prepared Statements, advanced data fetching, …)
Sorry for prev reply actually i had not notice that i am using same variable name in prev reply
my actual code is: -
<?php
-
$r_hostname = "hostname1";
-
$r_username = "username1";
-
$r_password = "pass1";
-
$link = mysql_connect($r_hostname,$r_username,$r_password);
-
$db = mysql_select_db("db_name1",$link);
-
?>
-
<?php
-
$hostname = "hostname2";
-
$username = "username2";
-
$password = "pass2";
-
$con = mysql_connect($hostname,$username,$password);
-
$db1 = mysql_select_db("db_name2",$con);
-
if ($con)
-
{
-
if ($db1)
-
{
-
echo "connected and selected ok";
-
}
-
else
-
{
-
echo "connected and selected failed";
-
}
-
}
-
else
-
{
-
echo "failed to connect to server";
-
}
-
?>
-
does it work now?
you might think over, how to verify the server connections, currently you completely neglect server1 errors.
line 13 would fail if the server connection (line 12) failed.
No its not working...
And server1 is that server where my registration page resides and i want to insert all data into database which is on server2 .
But i am not able to do this...
Thanks for your kind reply
any error messages? can you confirm both connections? have you access permission on server2?
I am getting this error Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'mysql50-30.wcl' (11001).
and for permission i have to check but how will i check that server2 has given me permission to access database. If not then how will i enable the access...
that's a strange host name, usually the host name is identical to the server name.
as for the permissions, ask the Administrator of server2.
If i am using only on single server this name as hostname ''mysql50-30.wcl'' then its working fine i can do all the think like select, delete and insert command. on this server but its not working when i am trying to connect on another server.
what do you get for "mysql.max_links" in php.ini (see phpinfo() in the MySQL section)?
hm, as expected…
could you PM (private messaging) me both host names, so that I can try if I get the same errors?
send me ur email id or how can i send PM via bytes
go to "User Control Panel" (click on your username just below the Bytes logo). in the left side menu there is the "Private Messages" group, click on "Send New Message". use "Dormilich" (w/o the quotes) as recipient. type message. click on the "Submit Message" button when you’re done. ;)
alternatively, click on my username, this brings you to my public profile. go to the "Contact Info" tab, click on "Send a Private Message …". proceed as above.
i have sent you the message with all the details...
thanks
1) can't connect to second server (hostname (chessimmigration.com) unknown) but it should work for you since it's your localhost
2) can find first server, but can't establish connection - $c1 = mysql_connect('chessglobalproperties.com', $user, $pass);
-
-
Warning: mysql_connect(): Lost connection to MySQL server at 'reading initial communication packet', system error: 61
after some research I found out that "system error: 61" means that you can only connect this particular DB with "localhost" as host name (i.e. not from outside). you need to alter the mysql conf file to get this working.
note: to pass the socket you need to use MySQLi
thank you very much for your co-operation...
i will do the same according to your reply...
hi ... i have same problem.. i have two databases from two different server and i want to connect in one php page but its giving me error like...
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'www.domain2.com'..
Please help...
Thanks in advance..
the second server must allow remote connection …
i have the problem in connecting two different database server, actually i want to take out data from MySQl table and want to istore it into MsSQl databse on the same page, i tried using mysql_connect() and mssql_conect() to connect with databases
bum i m getting 500 error that is internal server error plz help me ..!! thnaks in advanced
first make sure that both servers are properly installed (should be the least problem), then make sure PHP has both the mysql and mssql extensions installed. if that is also given, ask your host’s support.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: beck4353 |
last post by:
Hi,
I am using VS.NET Arch. and I am having problems
connecting to ANY database. I am trying to a either a
SqlConnection or OleDBConnection object to my project.
When I try to define the...
|
by: Wonderinguy |
last post by:
Our websphere application uses a generic application userid to connect
and query db2 on z/os via DB2 connect. The end user,logs in to the
application using
his regular userid, which is then...
|
by: Marcus |
last post by:
Hello!
I'm trying to write a VB.NET program that connects to a AS/400 Server.
I've tried almost everything, but it will not connect.
I've tried to set up a DSN using the Client Access...
|
by: Scott Holland |
last post by:
HELP - Need to connect to DB2 database on AIX from NT server. Also
AS/400 from NT Server
-- I am experienced in ORACLE and a novice at DB2. What tools would
be the equivalent of Net*8 or...
|
by: Fabian Knopf |
last post by:
Hi friends,
i have a unix machine PC1 where a database is running ( IBM DB2 V8.1 ) .
Then i have another machine PC2 i installed there also ( IBM DB2 V8.1 ). On
PC2 i installed unixODBC. To...
|
by: mayamorning123 |
last post by:
A comparison among six VSS remote tools including SourceOffSite ,
SourceAnyWhere, VSS Connect, SourceXT, VSS Remoting, VSS.NET
To view the full article, please visit...
|
by: Daniel Bass |
last post by:
I setup a asp.net project running on http://localhost/ which connects to a
database on another server running sqlserver...
I was able to connect to the database and create my application no...
|
by: traceable1 |
last post by:
I have a couple new servers - Windows 2003 R2 - with SQL Server 2000
SP4 installed. They are all Active/Active clustered instances (my
first ones).
I am trying to create database links to other...
|
by: MSK |
last post by:
Hi,
I am a newbie to .NET/Networking
if I develop a project in
1. VB.NET + SQL server database
2. ASP.NET + SQL server database
3. .NET ( vb or asp) + Access database
|
by: zgh1970 |
last post by:
Hi, All,
I have some question on the alternate server for the DB connection on
db2 connect server.
There is one db2 connection to one host database on the server with
the following cfg:
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |