views:

64

answers:

4

How can I connect from one website to database of another website in php.

A: 

You add the connection details in config.php or where you store them, and another-website.com or the IP to the host url (You probably have localhost there), then the username and the password.

True Soft
+1  A: 

The other website will require their port to be open for yours to connect to. They will also need the database user to allow connections that are not just from the local machine.

If you have a fairly standard LAMP set-up, this will mean opening port 3306 on the database server so outside connections can be made, and a database user setting up that will be able to connect from the outside world.

Bear in mind their may be latency issues.

Kevin Sedgley
I want to use the database inside another server....I have given mysql_connect("<remote site ip>","username","password") and mysql_connect("<remote site domain>","username","password")....but both do not work.....can you tell me what more I can do.....I have the ftp details of both the sites....
shinod
Most setups would not allow non-local database connections out of the box. Allowing such connections over something as insecure as the internet is something that should not be undertaken lightly.
CurtainDog
A: 

Just swap (what I presume you are using) localhost to the address of the database on the other server.

eg mysql.mywebsite.com

Pez Cuckow
I want to use the database inside another server....I have given mysql_connect("<remote site ip>","username","password") and mysql_connect("<remote site domain>","username","password")....but both do not work.....can you tell me what more I can do.....I have the ftp details of both the sites....
shinod
So you don't have the mySQL details of either site? You need the username and password from them...
Pez Cuckow
I have the username and password of remote database. I don't have database for my website
shinod
Just use mysql_connect("<remote site ip>","<username>","<password>" or die(mysql_error())) I bet you don't have the righer user/pas
Pez Cuckow
A: 

You need to know where the other website's database server is located, and you'll need to be able to connect to the database from remote sources at some designated port. Once you're sure you know all those, as well as the login credentials, you can just connect as you would normally do your own database.

BoltClock