Connecting to remote database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Connecting to remote database

Post by GeXus »

I'm using plesk with several domains setup, I want to have multiple domains access a database on one of the domains. I assume this would be done by using a remote connection....... has anyone done this or have any insight as to how I would do this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Instead of using "localhost" as the host argument, you use the IP or domain name. The receiving database would have to be configured such that the user you are using has the rights to access from the given location you are requesting from.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I'm not sure how you go about doing this with Plesk specifically. What you need to do is set the permissions on the database to be accessible either from '%' (anywhere) or make multiple entries for each ip of each domain you're wanting to have access from. Then, when you're connecting to the DB from PHP, just connect like:

Code: Select all

$connection = mysql_connect('IP of server',$username,$password);
However, if all the domains are on the same server, you shouldn't need to do anything. All the domains could just connect to 'localhost' without a problem.

Update: Dang! I've been 'feyded'!
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply