php - OOP issue: Call to a member function prepare() on a non-object -


I am trying to use the PDO and so I am putting it into a waiter in my database class:

  class database {// DSN, username and password private $ mysql; Public function __ composition () {$ mysql = new PDO ($ this- & gt; DSN, $ this-> dbUsername, $ this- & gt; dbPassword); $ mysql- & gt; Set Attribution (PDO :: ATTR_UMLamp PREPARES, Incorrect); $ mysql- & gt; Set attribute (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION); $ This- & gt; mysql = $ mysql; } Public Function Database () {Return $ this- & gt; Mysql; }}   

and I'm calling the database method such as:

  class router database {public function login () {$ query = $ this extends ) - & gt; mysql () - & gt; Prepare ('SELECT * ...'); $ Query-> But execute (array (...)); ...}   

Although I keep the following error:

  Fatal error: Call a member function (on non-object) / Code>  

I have asked more knowledgeable people about myself, although I am still confused about why this will not work.

Thank you!

You Personal Access Modifier Private $ mysql; are using. It is protected $ mysql; Change to .

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -