0

Newbie question. I have a project that need to access other web database using PHP. Is it possible?

for example: I have a domain www.domain1.com with database1 and I have another domain www.domain2.com with database2 with different hosting. Can I access database1 from www.domain2.com which is also using database2?

Is it possible if it is the same hosting with 2 different domain?

1
  • Your database should be accessible from outside your machine. It could be a security hole, but it is possible. Commented Aug 22, 2012 at 8:56

7 Answers 7

1

Yes. In order to do that, just follow the other answers here.

But, in order to do things the right way, it is more recommendable to create some middleware between your web application and the remote database (e.g. SOAP, RESTful, or just raw ad-hoc XML). It will add security and decoupling.

Sign up to request clarification or add additional context in comments.

Comments

0

You can connect to as many databases as many your application requires.

Get started with:

http://dev.mysql.com/doc/refman/5.0/en/connecting.html

Make sure port of domain2 allows authentication from domain1 (or you can keep it open for all, NOT RECOMMENDED).

If you are saying about JOINING databases then, so far I have worked on many projects where we had multiple databases on same server. So HOST was not an issue.

Comments

0

Yes, as long as the server port is open for PHP hosting domain .

Comments

0

It is possible if

  • the remote database user is accepting connections from local script
  • the mysql port 3306 from machine2 is open for machine1

Comments

0

Yeah, if you use MySql you have to set it to allow remote connections and then pass the ip/domain of the remote db in the mysql connect function

Comments

0

Yeah as long as you have a port open 80 should do, make sure you let the host know so they can allow you an account through.

1 Comment

MySQL use 3306 by default. 80 is httpd.
0

if you can access other stuff outside your localhost you can just like this:

$conn2 = mysql_connect($otherhost, $otheruser, $otherpassword, true);
//the true at the end makes a new link

$query = mysql_query($your_query, $conn2); 

this just send a query to the other database

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.