php - Call to a member function query() on a non-object Error how to fix? -


i try every thing not working, please 1 check code?

this database.class.php file..

class database { public $db = null; public $libraries = null;  public function database( $config ) {     $this->connect( $config['host'], $config['user'], $config['pass'], $config['database'] ); } public function connect($host, $user, $pass, $db) {     $this->db = new mysqli( $host, $user, $pass, $db ); }  public function query( $sql ) {     $f = func_get_args( );     $i = 1;     while ( $i <= count( $f ) )     {         $args[] = addslashes( $f[$i] );         ++$i;     }     $query = $this->createquery( $sql, $args );     if ( !( $result = $this->db->query( $query ) ) )     {         exit( mysqli_error( $this->db ) );     }     return $result; }  public function fetch_assoc( $result ) {     return $result->fetch_assoc( ); }  public function createquery( $sql, $args ) {     $i = 0;     while ( $i != count( $args ) )     {         $sql = preg_replace( "/%s/", str_replace( "s", "\\s", $args[$i] ), $sql, 1 );         ++$i;     }     return $sql; } } 

and template.class.php file..

public function getpageinfo( $page ) { $result = $this->database->query( "select * `content` `name` = '%s'", $page );     $row = $result->fetch_assoc( );     if ( $result->num_rows == 0 )     {         return false;     }     return $row; } 

libraries included in index.php php.. first database.class.php 2nd template.class.php

and attached both files..

http://www.mediafire.com/?xuak9ub7lehkbun

charles sprayberry right. code posted here either incomplete or forget create instance of database class. first thing missing in code point defined class. class mydatabase {} missing. @ least hope wanted create 1 because using $this->. second thing used $this->db in connect() function, trying use $this->database in getpageinfo() function. please provide more info class, function getpageinfo() resides , how made instance of class.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -