|
Posted by Jerim on 08/17/07 17:00
On Aug 17, 10:17 am, Rik <luiheidsgoe...@hotmail.com> wrote:
> On Fri, 17 Aug 2007 17:02:52 +0200, Jerim <wyo...@gmail.com> 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):
> <?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'];
}
Navigation:
[Reply to this message]
|