Hi all,
I have the following two classes:
class Database
{
var $conn;
var $result;
var $number;
function conndb()
{
$this->conn = mysql_connect('localhost', 'user', 'password');
mysql_select_db('database');
}
function query($sql)
{
$this->result = mysql_query($sql);
$this->number = 1;
}
}
class Test
{
function test_ref($sql)
{
$test = new Database();
$test->query($sql);
$test->number = 6;
}
}
Here is a copy of the program itself:
$db = new Database;
$db->conndb();
$query = "select * from table";
$db->query($query);
$num_result = $db->number;
$ref_test = new Test;
$query = "select * from table";
$ref_test->test_ref($query);
$num_result = $db->number;
mysql_close();
echo 'completed test';
A new database object is created when the test_ref() method is executed of the Test class. How do I modify my code so that the test_ref() method uses the already created Database object? I did do a search and found two threads with basically the same question, but I could not get either solution to work. I've been coding in PHP for a couple years but just recently decided to try the object oriented approach. The above code is just me trying to see what I can do (playing around). :p
Thanks in advance,
Scott