Page 1 of 1

Displaying data from another host on web server

Posted: Wed Apr 11, 2007 6:31 am
by christian_phpbeginner
Hi everybody,

I do not know what do people call this...

A website namely http://www.abc.com but the database is located in http://www.alldata.com. Any actions that interacts with the data such as: Add, Edit, or Delete will only be do able in http://www.alldata.com, but not in http://www.abc.com. http://www.abc.com acts only as a website that displays contents added from http://www.alldata.com...

In short, the database is in http://www.alldata.com, and http://www.abc.com only displays data which were inserted into the database located in http://www.alldata.com


I am trying to google this, but I think I have not found the right keyword for this case, so the results returned were improper.

What do you call this (brown colored) ?
Is it possible to do it in PHP ?
Have any good resources about it ? (very appreciated !!)...

Thanks a lot,
Chris

NOTE:
Both domain are owned by the company where I work, so I am not trying to ask you how to hack any websites here.

Posted: Wed Apr 11, 2007 6:40 am
by aaronhall
If you're using MySQL, brown color = "mysql user permissions", probably

Posted: Wed Apr 11, 2007 6:55 am
by mentor
Using PHP you can connect to remote or local databases. You can specify database located on local or remote server when connecting to it using mysql_connect().

Are you looking for this?

Posted: Wed Apr 11, 2007 7:20 am
by christian_phpbeginner
mentor wrote:Using PHP you can connect to remote or local databases. You can specify database located on local or remote server when connecting to it using mysql_connect().

Are you looking for this?
Hi, well, actually I am not sure ... what do I have to pass in the parameter ?

Code: Select all

mysql_connect('http://www.alldata.com/localhost', 'username', 'password');
I know the url is http://www.alldata.com, but how do I get the host name and do I have to specify the port too ? It is worth a try...but what if the remote server only allows 'localhost' for its host ??

Thanks,
Chris

Posted: Wed Apr 11, 2007 7:26 am
by aaronhall
If the mysql server is connected to the internets, the host can give you the server's address. If it's not hooked into the internets, you're out of luck. If you get that all working, it's matter of setting the user permissions in mysql to allow the remote client to only read data.

Posted: Wed Apr 11, 2007 7:49 am
by christian_phpbeginner
aaronhall wrote:If the mysql server is connected to the internets, the host can give you the server's address. If it's not hooked into the internets, you're out of luck. If you get that all working, it's matter of setting the user permissions in mysql to allow the remote client to only read data.
The mysql server is not connected to the internet I guessed....I just tried what mentor was suggested...and the mysql_error said "LOST CONNECTION......". So is this mean that I can't get the data out of the database ? Is there any other way ?

Posted: Wed Apr 11, 2007 8:06 am
by volka
christian_phpbeginner wrote:'http://www.alldata.com/localhost'
that would be 'www.alldata.com'

Posted: Wed Apr 11, 2007 8:14 am
by christian_phpbeginner
volka wrote:
christian_phpbeginner wrote:'http://www.alldata.com/localhost'
that would be 'www.alldata.com'
Hi Volka, I have tried to change the host name into http://www.alldata.com, but still it says: "LOST CONNECTION....". Is this means that I can not connect to the database ? I am sure that the database username and password is correct.

Thanks,
Chris

Posted: Wed Apr 11, 2007 8:24 am
by volka
Please show more of your code - esp. the code block responsible for
christian_phpbeginner wrote:it says: "LOST CONNECTION...."

Danke

Posted: Wed Apr 11, 2007 8:32 am
by christian_phpbeginner
volka wrote:Please show more of your code - esp. the code block responsible for
christian_phpbeginner wrote:it says: "LOST CONNECTION...."
The MySQLConnection.php

Code: Select all

<?php
   function connectToMySQL() {
      static $conn;
      if (isset($conn)) {
         return $conn;
      }
      
      $conn = mysql_connect('www.alldata.com', 'myusername', 'mypassword');
      
      if (!$conn) {
   	     die ("Connection error. Either host, username, password, or database name is invalid, or left blank.");
   	  }   		
   	  getDatabaseName();
   	  
   	  return $conn;
   		
   }
   
   function getDatabaseName() {
      $dbName = "somedatabasename";
      
      if (!mysql_select_db($dbName))
   	  {
   	     return "Database with the name you specified does not exist.";
   	  } else {
   		 return mysql_select_db($dbName, connectToMySQL());
   	  }
   }
   
   
   
?>
The test.php file

Code: Select all

<?php
   require_once('MySQLConnection.php');
   
   $query = "SELECT addressID FROM tbladdress";
   $result = mysql_query($query, connectToMySQL());
   
   if (!$result) {
      die (mysql_error(connectToMySQL()));
   }
   
   if (mysql_num_rows($result) > 0) {
      echo 'Connection Established';
   }

?>
The url of the test.php:
http://www.tokoapple.com/myos/test.php

You can see the error there...

I appreciated this...

Posted: Wed Apr 11, 2007 8:40 am
by Maugrim_The_Reaper
Post the fill error, and the error code - then it's a manual click away as to what it means.

Chances are it's unable to access the database across the internet. If that's the case you'll need to either find an alternative means of securely pushing the data to your current server, or something else. Are the server physically separated? No networking at all between them?

Posted: Wed Apr 11, 2007 8:44 am
by christian_phpbeginner
Maugrim_The_Reaper wrote:Post the fill error, and the error code - then it's a manual click away as to what it means.

Chances are it's unable to access the database across the internet. If that's the case you'll need to either find an alternative means of securely pushing the data to your current server, or something else. Are the server physically separated? No networking at all between them?
And what alternatives do you suggest ?

The server is physically separated. And no networking between them...

Oh by the way, I have called the web hosting provider. And they said that in the mean while they will only support 'localhost' as the host name...this means, I need alternatives...

The error:
Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /home2/apple/public_html/myos/MySQLConnection.php on line 8

Can XML solve this problem ?? What alternatives do I have in this case ?

Thanks,
Chris

Posted: Wed Apr 11, 2007 9:03 am
by feyd
If alldata has facilities to provide the information/manipulation you need via XML requests, yes.

All solutions will depend on what alldata provides. You need to talk with them.

Posted: Wed Apr 11, 2007 9:07 am
by christian_phpbeginner
feyd wrote:If alldata has facilities to provide the information/manipulation you need via XML requests, yes.

All solutions will depend on what alldata provides. You need to talk with them.
Ok thanks ! I'll try...