I've got a PHP project with many classes, and a PDO Wrapper class that I got off the web that seems pretty good:
http://code.google.com/p/php-pdo-wrapper-class/
My classes look like this now:
class product {
__constructor($id = 0) {
//mysql_query and store the product row in $this->row;
}
edit($array) {
//another obvious mysql_query...
}
So they're very simple and I want to move all the mysql_query's to PDO for security. I've got the variable:
$db = new pdo('localhost', 'user', 'pass');
Working correctly defined in the top line of my include file, before the classes. However, I don't want to have to write:
global $db;
At the start of every function. I considered changing the __construct() function to be something more like:
__construct($id = 0, $db = null) {
$this->db = $db;
}
And then referencing from there, but the problem with that is that I then have to change every constructor in my whole website. Is there a way to solve this such that I am able to do the minuimum amount of editing the already existing code?