469,319 Members | 2,356 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Two MySQL servers, one script

I am attempting to put together one script that pulls data from one
database on its own server, and data from another database on its own
server, which is off-site.

Server 1 - Only allows shared memory access to the database. Also
disallows http:// includes. This is where the database of names is
stored. This is our internal MySQL server.

Server 2 - Only allows shared memory access to the database. So
anything that calls the connection has to be on the same server. This
is our external web server maintained by an outside party.

To get a list of names, I created a PHP page on Server 2 that simply
includes a script from Server 1. The script on Server 1 connects to
the database, runs the query and prints the names to the screen. I did
this, because we wanted the web page on our web server which is Server
2, but since the the MySQL on Server 1 only accepts shared memory
access, the script that called it had to be on the same server.

Now what I want to do is include the ages of each person. That is
information stored in a MySQL database on Server 2, the web server. I
can't modify the Script on Server 1 to include the database connection
on Server 2 since Server 2 also requires shared memory access. So I
tried putting an include file on Server 2 and calling it from Server
1, but Server 2 doesn't allow http:// includes.

Please keep in mind that I have had problems with the include. You
would think that being an include file, it would have access to all
the data on the page that called it. I have found this not to be the
case. The include script that I called, did not recognize variables
that were declared in the file that was calling it. Perhaps because it
was on another server? The only solution I could find was to pass the
variables to the include file through URL. So if I were to put another
include statement on the original page on Server 2, the off site
include doesn't have access to that database connection. Any help is
appreciated.

Aug 17 '07 #1
10 1592
On Aug 17, 9:11 am, Jerim <wyo...@gmail.comwrote:
I am attempting to put together one script that pulls data from one
database on its own server, and data from another database on its own
server, which is off-site.

Server 1 - Only allows shared memory access to the database. Also
disallows http:// includes. This is where the database of names is
stored. This is our internal MySQL server.

Server 2 - Only allows shared memory access to the database. So
anything that calls the connection has to be on the same server. This
is our external web server maintained by an outside party.

To get a list of names, I created a PHP page on Server 2 that simply
includes a script from Server 1. The script on Server 1 connects to
the database, runs the query and prints the names to the screen. I did
this, because we wanted the web page on our web server which is Server
2, but since the the MySQL on Server 1 only accepts shared memory
access, the script that called it had to be on the same server.

Now what I want to do is include the ages of each person. That is
information stored in a MySQL database on Server 2, the web server. I
can't modify the Script on Server 1 to include the database connection
on Server 2 since Server 2 also requires shared memory access. So I
tried putting an include file on Server 2 and calling it from Server
1, but Server 2 doesn't allow http:// includes.

Please keep in mind that I have had problems with the include. You
would think that being an include file, it would have access to all
the data on the page that called it. I have found this not to be the
case. The include script that I called, did not recognize variables
that were declared in the file that was calling it. Perhaps because it
was on another server? The only solution I could find was to pass the
variables to the include file through URL. So if I were to put another
include statement on the original page on Server 2, the off site
include doesn't have access to that database connection. Any help is
appreciated.
Tried moving all code from the include to the main file. All I left on
the include file was a connection to the database. Unfortunately, the
main file doesn't seem to be able to recognize the database connection
from the include file. The query only works when it is in the include
file.

Aug 17 '07 #2
Rik
On Fri, 17 Aug 2007 16:11:33 +0200, Jerim <wy****@gmail.comwrote:
I am attempting to put together one script that pulls data from one
database on its own server, and data from another database on its own
server, which is off-site.

Server 1 - Only allows shared memory access to the database. Also
disallows http:// includes. This is where the database of names is
stored. This is our internal MySQL server.

Server 2 - Only allows shared memory access to the database. So
anything that calls the connection has to be on the same server. This
is our external web server maintained by an outside party.

To get a list of names, I created a PHP page on Server 2 that simply
includes a script from Server 1. The script on Server 1 connects to
the database, runs the query and prints the names to the screen. I did
this, because we wanted the web page on our web server which is Server
2, but since the the MySQL on Server 1 only accepts shared memory
access, the script that called it had to be on the same server.

Now what I want to do is include the ages of each person. That is
information stored in a MySQL database on Server 2, the web server. I
can't modify the Script on Server 1 to include the database connection
on Server 2 since Server 2 also requires shared memory access. So I
tried putting an include file on Server 2 and calling it from Server
1, but Server 2 doesn't allow http:// includes.

Please keep in mind that I have had problems with the include. You
would think that being an include file, it would have access to all
the data on the page that called it. I have found this not to be the
case. The include script that I called, did not recognize variables
that were declared in the file that was calling it. Perhaps because it
was on another server?
Indeed.
The only solution I could find was to pass the
variables to the include file through URL. So if I were to put another
include statement on the original page on Server 2, the off site
include doesn't have access to that database connection. Any help is
appreciated.
Hmmms, it seems there's an epedemic of people including by HTTP (search
the recent archive of this group). While you can include the _output_ of
an php file by HTTP, a 'real' include, which will recognize your variables
can only be done using either the local filesystem or by including raw PHP
code from elsewhere instead of the result.

The fact that these 2 servers can hardly communicate is a real problem.
You'll either have to get the output data and link it to age 'manually'
with PHP, or you'll have to really think about the database(server) setup.
Preferably all related data on one server, possibly a master/slave
scenario.
--
Rik Wasmus
Aug 17 '07 #3
On Aug 17, 9:32 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 16:11:33 +0200, Jerim <wyo...@gmail.comwrote:
I am attempting to put together one script that pulls data from one
database on its own server, and data from another database on its own
server, which is off-site.
Server 1 - Only allows shared memory access to the database. Also
disallows http:// includes. This is where the database of names is
stored. This is our internal MySQL server.
Server 2 - Only allows shared memory access to the database. So
anything that calls the connection has to be on the same server. This
is our external web server maintained by an outside party.
To get a list of names, I created a PHP page on Server 2 that simply
includes a script from Server 1. The script on Server 1 connects to
the database, runs the query and prints the names to the screen. I did
this, because we wanted the web page on our web server which is Server
2, but since the the MySQL on Server 1 only accepts shared memory
access, the script that called it had to be on the same server.
Now what I want to do is include the ages of each person. That is
information stored in a MySQL database on Server 2, the web server. I
can't modify the Script on Server 1 to include the database connection
on Server 2 since Server 2 also requires shared memory access. So I
tried putting an include file on Server 2 and calling it from Server
1, but Server 2 doesn't allow http:// includes.
Please keep in mind that I have had problems with the include. You
would think that being an include file, it would have access to all
the data on the page that called it. I have found this not to be the
case. The include script that I called, did not recognize variables
that were declared in the file that was calling it. Perhaps because it
was on another server?

Indeed.
The only solution I could find was to pass the
variables to the include file through URL. So if I were to put another
include statement on the original page on Server 2, the off site
include doesn't have access to that database connection. Any help is
appreciated.

Hmmms, it seems there's an epedemic of people including by HTTP (search
the recent archive of this group). While you can include the _output_ of
an php file by HTTP, a 'real' include, which will recognize your variables
can only be done using either the local filesystem or by including raw PHP
code from elsewhere instead of the result.

The fact that these 2 servers can hardly communicate is a real problem.
You'll either have to get the output data and link it to age 'manually'
with PHP, or you'll have to really think about the database(server) setup.
Preferably all related data on one server, possibly a master/slave
scenario.

We have discussed changing the setup, but are limited in what we are
allowed to do and by how much time we could dedicate to a project.
Which is practically none. (If they would let us shut down the IT
department for a month or so, buy at least one heavy duty server,
merge everything on to it, and adjust the databases to be more
cohesive(15 years of various workers results in a hodge podge of
databases/tables), that would be great. But it isn't going to happen.)

You mention including raw PHP. I don't know what you mean by that.
Could you please describe the process vaguely, so I know what to
search for?

Aug 17 '07 #4
On Aug 17, 9:32 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 16:11:33 +0200, Jerim <wyo...@gmail.comwrote:
I am attempting to put together one script that pulls data from one
database on its own server, and data from another database on its own
server, which is off-site.
Server 1 - Only allows shared memory access to the database. Also
disallows http:// includes. This is where the database of names is
stored. This is our internal MySQL server.
Server 2 - Only allows shared memory access to the database. So
anything that calls the connection has to be on the same server. This
is our external web server maintained by an outside party.
To get a list of names, I created a PHP page on Server 2 that simply
includes a script from Server 1. The script on Server 1 connects to
the database, runs the query and prints the names to the screen. I did
this, because we wanted the web page on our web server which is Server
2, but since the the MySQL on Server 1 only accepts shared memory
access, the script that called it had to be on the same server.
Now what I want to do is include the ages of each person. That is
information stored in a MySQL database on Server 2, the web server. I
can't modify the Script on Server 1 to include the database connection
on Server 2 since Server 2 also requires shared memory access. So I
tried putting an include file on Server 2 and calling it from Server
1, but Server 2 doesn't allow http:// includes.
Please keep in mind that I have had problems with the include. You
would think that being an include file, it would have access to all
the data on the page that called it. I have found this not to be the
case. The include script that I called, did not recognize variables
that were declared in the file that was calling it. Perhaps because it
was on another server?

Indeed.
The only solution I could find was to pass the
variables to the include file through URL. So if I were to put another
include statement on the original page on Server 2, the off site
include doesn't have access to that database connection. Any help is
appreciated.

Hmmms, it seems there's an epedemic of people including by HTTP (search
the recent archive of this group). While you can include the _output_ of
an php file by HTTP, a 'real' include, which will recognize your variables
can only be done using either the local filesystem or by including raw PHP
code from elsewhere instead of the result.

The fact that these 2 servers can hardly communicate is a real problem.
You'll either have to get the output data and link it to age 'manually'
with PHP, or you'll have to really think about the database(server) setup.
Preferably all related data on one server, possibly a master/slave
scenario.
Just read where someone with a similar problem suggested renaming the
include file to .txt. Is that what you mean by raw PHP? This might
work, as the file that is being included, itself calls an include that
connects to the database. So even if I were to read the include file
as raw text, no one should be able to see the database connection
info.

Aug 17 '07 #5
Rik
On Fri, 17 Aug 2007 16:54:17 +0200, Jerim <wy****@gmail.comwrote:
>The fact that these 2 servers can hardly communicate is a real problem.
You'll either have to get the output data and link it to age 'manually'
with PHP, or you'll have to really think about the database(server)
setup.
Preferably all related data on one server, possibly a master/slave
scenario.


We have discussed changing the setup, but are limited in what we are
allowed to do and by how much time we could dedicate to a project.
Which is practically none.
Then you'll have to have a PHP script running on one server, get the
output of that on the other (using CSV or serialize() for the output comes
to mind), and link the related data on that server with it with a bunch of
queries.
You mention including raw PHP. I don't know what you mean by that.
On a typical HTTP request, PHP code will be executed, and all you get is
the output. If you however output the code itself (either by disabling PHP
(for that directory), giving it another non-processed extention, or by
'building PHP with PHP' (<?php echo '<?php echo "foo"; ?>' ?>)), it can be
processed on the requesting server.
Could you please describe the process vaguely, so I know what to
search for?
It wouldn't help you, as the code doesn't get executed on the server it
comes from in that case, but on the server doing the include. Think about
it, if I could just include from other servers by HTTP and have access to
their code, I could do something like this:

<?php
include('http://www.paypal.com');
mysql_query("UPDATE `balance` SET `amount` = 999999999999 WHERE `id` =
'me'");
?>

So, clearly it doesn't work that way.
--
Rik Wasmus
Aug 17 '07 #6
On Aug 17, 9:32 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 16:11:33 +0200, Jerim <wyo...@gmail.comwrote:
I am attempting to put together one script that pulls data from one
database on its own server, and data from another database on its own
server, which is off-site.
Server 1 - Only allows shared memory access to the database. Also
disallows http:// includes. This is where the database of names is
stored. This is our internal MySQL server.
Server 2 - Only allows shared memory access to the database. So
anything that calls the connection has to be on the same server. This
is our external web server maintained by an outside party.
To get a list of names, I created a PHP page on Server 2 that simply
includes a script from Server 1. The script on Server 1 connects to
the database, runs the query and prints the names to the screen. I did
this, because we wanted the web page on our web server which is Server
2, but since the the MySQL on Server 1 only accepts shared memory
access, the script that called it had to be on the same server.
Now what I want to do is include the ages of each person. That is
information stored in a MySQL database on Server 2, the web server. I
can't modify the Script on Server 1 to include the database connection
on Server 2 since Server 2 also requires shared memory access. So I
tried putting an include file on Server 2 and calling it from Server
1, but Server 2 doesn't allow http:// includes.
Please keep in mind that I have had problems with the include. You
would think that being an include file, it would have access to all
the data on the page that called it. I have found this not to be the
case. The include script that I called, did not recognize variables
that were declared in the file that was calling it. Perhaps because it
was on another server?

Indeed.
The only solution I could find was to pass the
variables to the include file through URL. So if I were to put another
include statement on the original page on Server 2, the off site
include doesn't have access to that database connection. Any help is
appreciated.

Hmmms, it seems there's an epedemic of people including by HTTP (search
the recent archive of this group). While you can include the _output_ of
an php file by HTTP, a 'real' include, which will recognize your variables
can only be done using either the local filesystem or by including raw PHP
code from elsewhere instead of the result.

The fact that these 2 servers can hardly communicate is a real problem.
You'll either have to get the output data and link it to age 'manually'
with PHP, or you'll have to really think about the database(server) setup.
Preferably all related data on one server, possibly a master/slave
scenario.
Found a suggestion that mentioned changing the included file to .txt,
which should read it in as raw PHP. I tried that. The problem is that
the file being called for inclusion itself calls another file on the
same server as itself. This file it calls is the database connection
info. By including the file on a seperate server, the include file can
no longer access the needed database connection.

Aug 17 '07 #7
Rik
On Fri, 17 Aug 2007 17:02:52 +0200, Jerim <wy****@gmail.comwrote:
>The fact that these 2 servers can hardly communicate is a real problem.
You'll either have to get the output data and link it to age 'manually'
with PHP, or you'll have to really think about the database(server)
setup.
Preferably all related data on one server, possibly a master/slave
scenario.

Just read where someone with a similar problem suggested renaming the
include file to .txt. Is that what you mean by raw PHP?
Yep.
This might
work,
Nope.
as the file that is being included, itself calls an include that
connects to the database.
Which would be non-existant on the server it executes on. PHP-code served
that way is plain text, NOTHING of the envirnoment on the other server
will be accessable.
So even if I were to read the include file
as raw text, no one should be able to see the database connection
info.
Clearly not.

TO give you an illustration of the terrible hoops you have to jump through:

Server 1 (people.php):
<?php
mysql_connect();
mysql_select_db();
$q = mysql_query('SELECT id, name FROM people');
$return = array();
while($row = mysql_fetch_assoc($q)) $return[] = $row;
echo serialize($return);
?>

Server 2:
<?php
$people = unserialize(file_get_contents('http://server1/people.php'));
//includes would be tedious:
// ob_start();
// include('http://server1/people.php');
// $people = unserialize(ob_get_clean());
//
if(is_array($people) && !empty($people)){
mysql_connect();
mysql_select_db();
foreach($people as $person){
$bday = mysql_query('SELECT `birthday` FROM `birthdays` WHERE id =
'.$person['id']);
$date = $bday ? mysql_result($bday,0,'birthday') : 'unknown';
echo "{$person['id']} {$person['name']} {$date}<br>";
}
}
?>

Which might be somewhat streamlined by fetching all the birthdays in one
query to an array indexed by 'id', and linking to it in the foreach loop
of $persons, it's still terribly inconvenient.
--
Rik Wasmus
Aug 17 '07 #8
On Aug 17, 10:17 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 17:02:52 +0200, Jerim <wyo...@gmail.comwrote:
The fact that these 2 servers can hardly communicate is a real problem.
You'll either have to get the output data and link it to age 'manually'
with PHP, or you'll have to really think about the database(server)
setup.
Preferably all related data on one server, possibly a master/slave
scenario.
Just read where someone with a similar problem suggested renaming the
include file to .txt. Is that what you mean by raw PHP?

Yep.
This might
work,

Nope.
as the file that is being included, itself calls an include that
connects to the database.

Which would be non-existant on the server it executes on. PHP-code served
that way is plain text, NOTHING of the envirnoment on the other server
will be accessable.
So even if I were to read the include file
as raw text, no one should be able to see the database connection
info.

Clearly not.

TO give you an illustration of the terrible hoops you have to jump through:

Server 1 (people.php):
<?php
mysql_connect();
mysql_select_db();
$q = mysql_query('SELECT id, name FROM people');
$return = array();
while($row = mysql_fetch_assoc($q)) $return[] = $row;
echo serialize($return);
?>

Server 2:
<?php
$people = unserialize(file_get_contents('http://server1/people.php'));
//includes would be tedious:
// ob_start();
// include('http://server1/people.php');
// $people = unserialize(ob_get_clean());
//
if(is_array($people) && !empty($people)){
mysql_connect();
mysql_select_db();
foreach($people as $person){
$bday = mysql_query('SELECT `birthday` FROM `birthdays` WHERE id =
'.$person['id']);
$date = $bday ? mysql_result($bday,0,'birthday') : 'unknown';
echo "{$person['id']} {$person['name']} {$date}<br>";
}}

?>

Which might be somewhat streamlined by fetching all the birthdays in one
query to an array indexed by 'id', and linking to it in the foreach loop
of $persons, it's still terribly inconvenient.
It seems that I am getting somewhere thanks to your help. I am not
getting any errors. Still not quite there yet. Here is roughly what I
have.

File to be included:
<?
$query= "SELECT name
FROM `names` name";
$result = mysql_query($query, $database) or die('Query failed: ' .
mysql_error());
$return = array();
while($row = mysql_fetch_assoc($result)) $return[] = $row;
echo serialize($return);
?>

Which I take it, should return an array of $return[]. The file that
calls the include has:
<?
$name= unserialize(file_get_contents('https//www.website.com/
include.php'));
?>

Two things I need to do here, are 1) see if the array returned any
data and 2) print the names to screen.

For the first problem I am guessing I can just check to see if the
array, $return[], is empty. (Seem to recall some isempty() function)

For the second problem, I am wondering if this would work:
while ($row = mysql_fetch_array($name)) {
print_r($return['name']);
}

Or should loop through with a variable such as:

x=0;
while (x<=$num_rows){
print_r($return['x'];
}

Aug 17 '07 #9
NC
On Aug 17, 7:11 am, Jerim <wyo...@gmail.comwrote:
>
I am attempting to put together one script that pulls data from one
database on its own server, and data from another database on its own
server, which is off-site.

Server 1 - Only allows shared memory access to the database. Also
disallows http:// includes. This is where the database of names is
stored. This is our internal MySQL server.

Server 2 - Only allows shared memory access to the database. So
anything that calls the connection has to be on the same server. This
is our external web server maintained by an outside party.

To get a list of names, I created a PHP page on Server 2 that simply
includes a script from Server 1.
Ain't going to work. Remote include() only includes the output of a
script, not the executable code.

What you need is to deploy a Web service provider on Server 2 and
consume the service from Server 1. Ideally, though, you should allow
access to Server 2 databases from Server 1 (preferably via SSL).

Cheers,
NC

Aug 17 '07 #10
On Aug 18, 2:06 am, NC <n...@iname.comwrote:
On Aug 17, 7:11 am, Jerim <wyo...@gmail.comwrote:
<snip>
Ain't going to work. Remote include() only includes the output of a
script, not the executable code.
<snip>

True, only if the file is parseable by PHP. Something, like
foo.php.txt will definitely be a trouble.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Aug 18 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Duane Winner | last post: by
2 posts views Thread by David | last post: by
5 posts views Thread by linuxlover992000 | last post: by
6 posts views Thread by Mitesh | last post: by
10 posts views Thread by Caffeneide | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.