473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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 1789
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marc | last post by:
Hello, Newbie here..... Searching and working this for a week now. We too are having the same problems. Using MySql 4.0.14 and there are "no problems" at all.
0
by: Duane Winner | last post by:
Hello all - I'm having a small problem with the mysql startup script that ships with MySQL-3.23.56-1. I'm running on RedHat Linux. It works fine, but I have a backup server that runs a script...
2
by: David | last post by:
My organization currently has 2 different MySQL database servers. We are in the process of moving the databases from Server A to Server B and have Server B be our primary database server. I've...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
5
by: linuxlover992000 | last post by:
I am a newbie in the world of MySQL. In fact I enabled it in my Linux box only because it is required to run WordPress (the blogging software). I was trying to plan ahead and figure out a way to...
6
by: Mitesh | last post by:
How can I programattically retrieve MySQL server's port value through PHP?
1
Ajm113
by: Ajm113 | last post by:
Ok, when I was new to this I had this problem and I bet a lot of other people did when they where new to PHP and Mysql. So this mite be your question; "Ok, no errors or warnings in mysql and php so...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
10
by: Caffeneide | last post by:
I'm using a php script which performs three xml queries to other three servers to retrieve a set of ids and after I do a query to mysql of the kind SELECT * FROM table WHERE id IN ('set of ids');...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.