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
Post a Comment