mysql - Call to a member function query() on a non-object in PHP -


I have a little problem converting from mysql to mysqli, this error has been displayed in: Member Function on a non-object Call query ()

here is config.php:

  $ db = new mysqli ($ dbhost, $ dbuser, $ dbpass, $ dbname); If ($ db-> Connect_error) {trigger_error ('error:'. $ Db-> Connect_uper, E_USER_ERROR); }   

And here is the function in statistics.php:

  public function getTotalServerCount () {$ sql = 'SELECT * control from paneel.server'; $ Total = $ db- & gt; Query ($ sql); Counterpart $ total; }   

Please note that this function is contained in class in the name of statistics.

I understand that the original code was done in a procedural way and I am trying to convert it to an object oriented way, but I have not yet found any solution.

<<>> $ db is the property of the class that can < / p>

  $ total = $ this-  $ db  This function is undetermined in scope, & gt; Db- & gt; Query ($ SQL); You can optionally pass it as a parameter:  
  public function getTotalServerCount ($ db) {// ... < / Code>   

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 -