Passing objects between php files
Posted: Thu Jul 03, 2008 10:53 pm
Hi,
How do I pass objects between php files? I've tried using $_GLOBALS, $GLOBAL, $_REQUEST and can't get it to work. I'm basically trying to pass mysql results to another php file...example psuedo-code below:
//in myClass.php
class myClass
{
function search() {
$sql = "SELECT * FROM myTable ";
$result = mysql_query($sql) or die (mysql_error());
$GLOBALS['results'] = $result;
$GLOBALS['myclass'] = $this;
$GLOBALS['test'] = 2;
header("Location: search_results.php");
}
}
//in search_results.php
echo $GLOBALS['test']; //echos empty string, when it should echo 2
$myclass = $GLOBALS['myclass'];
$myclass->search(); //error saying that $myclass is not an object
Any help is appreciated.
Thanks.
How do I pass objects between php files? I've tried using $_GLOBALS, $GLOBAL, $_REQUEST and can't get it to work. I'm basically trying to pass mysql results to another php file...example psuedo-code below:
//in myClass.php
class myClass
{
function search() {
$sql = "SELECT * FROM myTable ";
$result = mysql_query($sql) or die (mysql_error());
$GLOBALS['results'] = $result;
$GLOBALS['myclass'] = $this;
$GLOBALS['test'] = 2;
header("Location: search_results.php");
}
}
//in search_results.php
echo $GLOBALS['test']; //echos empty string, when it should echo 2
$myclass = $GLOBALS['myclass'];
$myclass->search(); //error saying that $myclass is not an object
Any help is appreciated.
Thanks.