473,410 Members | 1,904 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,410 software developers and data experts.

PHP/MySQL connecting 2 databases from 2 servers/hosts

Hey so I have been doing a lot of research and haven't found too much.

I am working on a project where I need to select calendar events from 2 different calenders (on 2 different servers) and display the combined events on 1 calendar. In order to do this I am going to create a script that grabs the data from the database on server a and insert it into the database on server b.

In order to do this I need to make 2 different mysql connections. Just to clearify, I understand how to connect to a database and display data from a table.

For my database i just did a normal connect:
Expand|Select|Wrap|Line Numbers
  1. $hostname_mywebsite = "localhost";
  2. $database_mywebsite = "my_database";
  3. $username_mywebsite = "my_username";
  4. $password_mywebsite = "my_password";
  5.  
  6. $mywebsite = mysql_pconnect($hostname_mywebsite, $username_mywebsite, $password_mywebsite) or trigger_error(mysql_error(),E_USER_ERROR); 
  7. mysql_select_db($database_mywebsite, $mywebsite);
  8.  
  9. etc....
  10.  
  11.  
I figured to connect to the database on the other server i'll have to create a mysql connect as well. I wasn't sure what I need to put under hostname? I know localhost won't work because it is a different server. I tried using the domain name theotherwebsite.com and the IP address, and neither worked?

Is that the correct way of doing it? Or do I need to configure both servers to allow connections from non-local servers? And depending on the server (i.e. linux, mac, etc..) will the server be configured in a different manner?
Nov 26 '11 #1
3 2263
Your script will connect the remote server which is not located on your local host with its external public IP Adress. The User you are using to connect needs to have privileges to connect from that ip adresse.

At normal user/database configs users always only have access from localhost.

In the mysql Database (called mysql) you will find two tables "user" and "db" ... at both tables you need to add "%" as host (replacing localhost) or if you always will connect from the same ip, set it to the ip Adress.

After editing the tables, run an "flush privileges" SQL to realod the users into mysql deaemon.

AND ... add "true" as last parameter to your mysql_connect to tell PHP it is a new connection so it wont' try to use the localhost resource you already connected to (read the php.net manual for that)
Nov 26 '11 #2
ok that was very helpful, are there any security measures that i need to take into consideration? it sounds like it shouldn't be a problem, because of what you said; that the permission to connect is set by ip. also i am doing this as a volunteer job, im not sure of their public ip address of the top of my head. i just used ping thewebsite.com to get the ip, that should get me the correct ip address to use for the hostname, correct?

Also, i checked the database, the default mysql database is emtpy, they are using a database that they created, which means there are no table named 'user' or 'db'. i did a search of the database and there are no fields that contain the value, 'localhost'? any tips?

thanks!
Nov 26 '11 #3
say:

your script is located on "mylocalwebsite.com" and it is connecting to the database-server on "thewebsite.com".

Getting the target ip by PING is ok but THEY need to have YOUR IP to be set into their MySQL Server for the user and db permissions.

Speaking about security .. well .. data will be send through the inernet ... what should i say :-) security flaws are everywhere and i bet you are not going to add SSL / X509 MySQL Auth stuff.
Nov 26 '11 #4

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

Similar topics

5
by: ysrana2001 | last post by:
In my office we have two SCO OpenServer (TM) Release 5 servers with two different terminals network. Now we have to join both server and windows server to share some file. Before we use generally...
1
by: kev | last post by:
Is it possible to connect to different databases on different servers so i can merge them as one. I heard there is a tool that does this but still to come accross it any help appreciated.
1
by: Dave Crypto | last post by:
Hi there, SUMMARY: 1) When I use phpadmin to export a large database, the file created on my local PC never containes all the tables and information. It seems to max out at about 10mb. 2)...
5
by: news | last post by:
I have a new situation I'm facing and could use a suggestion or two, as I don't seem to be able to think in the abstract very well. We have a local server which holds all of our image files. We...
4
by: Nel | last post by:
I am trying to understand the best way to extract a list of users from a table based upon their location. To do this I have a table containing all the UK postcodes with a grid reference x & y....
0
by: Howard | last post by:
I have Apache Web Server 2.0.55 installed locally with MySQL 5.0.18-nt, and of course PHP 5.1.2 I also have installed phpMyAdmin. It is accessible through http://localhost/phpMyAdmin. The pathing...
2
code green
by: code green | last post by:
How do I update the same MySql database from server 1 to server 2 using a php script. I can make the connection between the two and 'see' the tables using SHOW TABLES. Now I want to replace the...
3
by: byrocat | last post by:
Up until now, I've been working with V& DB2 UDB databases, using Embarcadero DBArtisan as my GUI tool. I also have other tools that I use in my day-to-day job so running directly on the server via...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
30
by: iheartvba | last post by:
Hi, I already have 3 Databases running: A. they all have the same tables and the same structure B. There is no 1 Master table they are all separate tables What I want to do is to merge them...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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 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.