In this case, you can be more organized. Consider this class as a model that will expand the base class of the model. Instead of using it directly, mysql_queryuse a database class and using which you can perform database operations, such as querying a database. insert into database etc. set this as a db object in the base class of the model. Like a simple demonstration
class model{
public function __construct()
{
$this->db = new Database(HOST,USER,PASS,DB);
}
}
class Post extends model{
public $post;
public function querySinglePost($value){
$this->post = $this->db->query("select query");
return $this->post;
}
}
You will call as
$ObjPost = new Post();
$post = $ObjPost->querySinglePost(1);
source
share