2
I am changing my PDO application to Mysqli since I will only use SQL even.
I create the connection on the main controller so others can open it:
class Controller {
    function __construct() {
    }
    public function openDB() {
        //$options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING);
        $this -> db = new mysqli(DB_HOST, DB_USER, DB_PASS);
        if ($this -> db -> connect_errno) {
            die("Failed to connect to MySQL: " . $this -> db -> connect_error);
        } else {
        return $this -> db;
        }
    }
}
An example of use in the daughter class:
class teste extends controller {
    function index() {
        $db = $this -> openDB();
        $stmt = $db->prepare("SELECT * FROM teste WHERE id = 1");
        $stmt->execute();
    }
}
and this comes back to me:
Fatal error: Call to a Member Function execute() on a non-object in
i give a var_dump in the variable $db to test if the connection is OK and it returns me a normal array...
The only night was the lack of selecting the database and data.
– rray
Damn, how did I not see that? and gave no error rsrs, Thank you!
– Thiago
Do not select the bank not from the same error.
– rray
@rray put as answer
– bfavaretto