Two MySQL servers, one script
Two MySQL servers, one script
am 17.08.2007 16:11:33 von Jerim
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.
Re: Two MySQL servers, one script
am 17.08.2007 16:26:12 von Jerim
On Aug 17, 9:11 am, Jerim wrote:
> 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.
Re: Two MySQL servers, one script
am 17.08.2007 16:32:45 von luiheidsgoeroe
On Fri, 17 Aug 2007 16:11:33 +0200, Jerim wrote:
> 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
Re: Two MySQL servers, one script
am 17.08.2007 16:54:17 von Jerim
On Aug 17, 9:32 am, Rik wrote:
> On Fri, 17 Aug 2007 16:11:33 +0200, Jerim wrote:
> > 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?
Re: Two MySQL servers, one script
am 17.08.2007 17:02:52 von Jerim
On Aug 17, 9:32 am, Rik wrote:
> On Fri, 17 Aug 2007 16:11:33 +0200, Jerim wrote:
> > 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.
Re: Two MySQL servers, one script
am 17.08.2007 17:06:09 von luiheidsgoeroe
On Fri, 17 Aug 2007 16:54:17 +0200, Jerim wrote:
>> The fact that these 2 servers can hardly communicate is a real proble=
m.
>> You'll either have to get the output data and link it to age 'manuall=
y'
>> 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 com=
es =
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 P=
HP =
(for that directory), giving it another non-processed extention, or by =
'building PHP with PHP' (' ?>)), 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 abo=
ut =
it, if I could just include from other servers by HTTP and have access t=
o =
their code, I could do something like this:
include('http://www.paypal.com');
mysql_query("UPDATE `balance` SET `amount` =3D 999999999999 WHERE `id` =3D=
=
'me'");
?>
So, clearly it doesn't work that way.
-- =
Rik Wasmus
Re: Two MySQL servers, one script
am 17.08.2007 17:09:03 von Jerim
On Aug 17, 9:32 am, Rik wrote:
> On Fri, 17 Aug 2007 16:11:33 +0200, Jerim wrote:
> > 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.
Re: Two MySQL servers, one script
am 17.08.2007 17:17:50 von luiheidsgoeroe
On Fri, 17 Aug 2007 17:02:52 +0200, Jerim wrote:
>> The fact that these 2 servers can hardly communicate is a real proble=
m.
>> You'll either have to get the output data and link it to age 'manuall=
y'
>> 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 serve=
d =
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 throu=
gh:
Server 1 (people.php):
mysql_connect();
mysql_select_db();
$q =3D mysql_query('SELECT id, name FROM people');
$return =3D array();
while($row =3D mysql_fetch_assoc($q)) $return[] =3D $row;
echo serialize($return);
?>
Server 2:
$people =3D unserialize(file_get_contents('http://server1/people.php')); =
//includes would be tedious:
// ob_start();
// include('http://server1/people.php');
// $people =3D unserialize(ob_get_clean());
//
if(is_array($people) && !empty($people)){
mysql_connect();
mysql_select_db();
foreach($people as $person){
$bday =3D mysql_query('SELECT `birthday` FROM `birthdays` WHERE id =3D=
=
'.$person['id']);
$date =3D $bday ? mysql_result($bday,0,'birthday') : 'unknown';
echo "{$person['id']} {$person['name']} {$date}
";
}
}
?>
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
Re: Two MySQL servers, one script
am 17.08.2007 19:00:05 von Jerim
On Aug 17, 10:17 am, Rik wrote:
> On Fri, 17 Aug 2007 17:02:52 +0200, Jerim wrote:
> >> 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):
>
> 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:
>
> $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}
";
> }}
>
> ?>
>
> 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'];
}
Re: Two MySQL servers, one script
am 17.08.2007 21:11:14 von Jerim
Wondering if using functions wouldn't be a better way to go. Include
the file form the distant server, and that include file contains a
function that returns what I need. Not sure if that will work in this
circumstance.
Re: Two MySQL servers, one script
am 17.08.2007 21:38:18 von Jerim
On Aug 17, 2:11 pm, Jerim wrote:
> Wondering if using functions wouldn't be a better way to go. Include
> the file form the distant server, and that include file contains a
> function that returns what I need. Not sure if that will work in this
> circumstance
Nope, it doesn't recognize the function.
Re: Two MySQL servers, one script
am 17.08.2007 23:06:14 von nc
On Aug 17, 7:11 am, Jerim wrote:
>
> 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
Re: Two MySQL servers, one script
am 18.08.2007 16:59:43 von ng4rrjanbiah
On Aug 18, 2:06 am, NC wrote:
> On Aug 17, 7:11 am, Jerim wrote:
> Ain't going to work. Remote include() only includes the output of a
> script, not the executable code.
True, only if the file is parseable by PHP. Something, like
foo.php.txt will definitely be a trouble.
--
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/