I am converting a my site to PDO and after about 200 scripts I am very near the end. Every script accesses the same functions script. Within the functions script I have a Database class which looks like so:
class Database {
private $db_con = ''; //stores the connection
public function db_login(){
//log into the database
}
public function db_control($query, $params){
//run the query
}
}
//initiate the class and log in
$db = new Database();
$db->db_login();
Both of these functions work fine and for every type of query, hence why I am almost finished. However, I have run into a problem.
I have a standalone function on a script I am working on which is used several times within the script. I usually run the db_control:
$results = $db->db_control($query, $params);
But running it from within a function:
function func(){
$results = $db->db_control($query, $params);
}
Returns the error.
Fatal error: Call to a member function db_control() on a non-object in C:....php on line 39
What am I doing wrong? The class is definitely being initiated as other queries on the script work fine when this function is removed. How can I access db_control() from within a standalone function?
Thank you,
Joe