Displaying data from another host on web server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Displaying data from another host on web server

Post 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.
Last edited by christian_phpbeginner on Wed Apr 11, 2007 6:50 am, edited 1 time in total.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

If you're using MySQL, brown color = "mysql user permissions", probably
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post 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?
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Post 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
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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.
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Post 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 ?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

christian_phpbeginner wrote:'http://www.alldata.com/localhost'
that would be 'www.alldata.com'
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please show more of your code - esp. the code block responsible for
christian_phpbeginner wrote:it says: "LOST CONNECTION...."
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Danke

Post 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...
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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?
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Post 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
Last edited by christian_phpbeginner on Wed Apr 11, 2007 9:03 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Post 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...
Post Reply