I'm new to OO PHP and I have created a Database Class, And I have a problem when I build My SELECT Query With the JOIN method.
If I do the Querys in Functions.
<?php
require_once("class.Database.php");
function test1($db) {
$test1 = $db->Select("*")
->From("Table1")
->Join("Table2","table_2_id = table_1_id")
->Join("Table3","table_3_id = table_2_id")
->BuildSelect();
return $test1;
}
function test2($db) {
$test2 = $db->Select("*")
->From("Table4")
->Join("Table5","table_5_id = table_4_id")
->Join("Table6","table_6_id = table_5_id")
->BuildSelect();
return $test2;
}
echo test1($db);
echo "<br>";
echo test2($db);
?>
The problem is that the First function - test1 will print out -
SELECT * FROM Table1 LEFT JOIN Table2 ON table_2_id = table_1_id LEFT JOIN Table3 ON table_3_id = table_2_id
- Which is good
But then the second function test2 will print out -
SELECT * FROM Table4 LEFT JOIN Table2 ON table_2_id = table_1_id LEFT JOIN Table3 ON table_3_id = table_2_id LEFT JOIN Table5 ON table_5_id = table_4_id LEFT JOIN Table6 ON table_6_id = table_5_id
The test2 function seems to be printing out the Values from the test1 function's JOIN method as well as its own Values from the JOIN method.
Can someone please help.