I have a PHP database class that connects to MySQL and completes all the PDO code, and I use it to query the database. Basically in the page controller, I create a new object:
$db = new Database($dbConfig);
Then I can get the data from the database using the prepared query:
$params = array('username' => $username);
$result = $db->preparedSelect('select password, salt from users where username = :username', $params);
Which copies the results of the PDO statement to the new destination array and only returns the database results back to the calling page. I go through them with a simple foreach as follows:
foreach ($result as $key => $val)
{
$password = $val['password'];
$salt = $val['salt'];
}
So let's say that I want another class to use my $ db object so that it can access the database in some methods. At the moment, another class is as follows:
class General
{
private $db;
public function __construct($db)
{
$this->db = $db;
}
}
, , :
public function __construct(&$db)
{
$this->db = $db;
}
, . $db , , , , , .
- PHP5 $db & $db? PHP5 , , Java, , , . . ?
!