>**Fatal error**: Uncaught Error: Call to a member function `select()` on `string` in C:\OSPanel\domains\phplog\index.php:12 *Stack trace:* #0 {main} thrown in C:\OSPanel\domains\phplog\index.php on line 12 Here is the code index.php
<?php include 'config/config.php'; ?> <?php include 'libraries/database.php'; ?> <?php include 'includes/header.php'; ?> <?php //Create DB Object $db = 'database'; //Create Query $query = "SELECT * FROM posts"; //Run Query $posts = $db->select($query); ?> <?php if($posts) : ?> <div class="blog-post"> <h2 class="blog-post-title">Another blog post</h2> <p class="blog-post-meta">December 23, 2013 by <a href="#">Jacob</a></p> <p>text.</p> <a class="readmore" href="post.php?id=1">read more</a> </div><!-- /.blog-post --> <div class="blog-post"> <h2 class="blog-post-title">Another blog post</h2> <p class="blog-post-meta">December 23, 2013 by <a href="#">Jacob</a></p> <p>text.</p> <a class="readmore" href="post.php?id=1">read more</a> </div><!-- /.blog-post --> <?php else : ?> <p>Thete are no posts yet</p> <?php endif; ?> <?php include 'includes/footer.php'; ?> Here is the database.php code
<?php class database{ public $host = db_host; public $username = db_username; public $password = db_pass; public $db_name = db_name; public $link; public $error; /* * Class Constructor */ public function __construct(){ //Call Connect Function $this->connect(); } /* * Connector */ private function connect() { $this->link = new mysqli($this->host, $this->username, $this->password, $this->db_name); if(!$this->link) { $this->error = "Connection Failed: ".$this->link->connect_error; return false; } } /* * Select */ public function select($query) { $result = $this->link->query($query) or die($this->link- >error.__LINE__); if($result->num_rows > 0){ return $result; } else { return false; } } /* * Insert */ public function insert($query) { $insert_row = $this->link->query($query) or die($this->link- >error.__LINE__); //Validate Insert if($insert_row) { header("Location: index.php?msq=".urlencode('Record insert')); exit(); } } /* * Update */ public function update($query) { $update_row = $this->link->query($query) or die($this->link- >error.__LINE__); //Validate update if($update_row) { header("Location: index.php?msq=".urlencode('Record update')); } } } ?> And here is the connection code itself config.php database
<?php define('db_host', 'localhost'); define('db_user', 'root'); define('db_pass', ''); define('db_name', 'blog'); ?>