status: accepting the only one answer choice. with thanks.
shouldn't I use static functions and self::
instead of $this->
in here . I would use this class Dao as a super class
in all of my model classes.
The Dao class will be the super class of all the model classes.
Should it be singleton? should it use static?
any tips ?
<?php
class Dao extends Object{
private $con;
//will put this in defines includes file. Or user from WP.
private $dbhost = "localhost";
private $dbname = "wpm";
private $dbuser = "root";
private $dbpass = "root";
public function __construct() {
if(!$this->con){
$this->con = new PDO("mysql:host=$this->dbhost;dbname=$this->dbname",$this->dbuser,$this->dbpass); //will make it generic.
}
}
protected function getCon(){
if(!$this->con){
$this->con = new PDO("mysql:host=$this->dbhost;dbname=$this->dbname",$this->dbuser,$this->dbpass);
}
return $this->con;
}
protected function executeQuery($query, $fetchType, $paramArray){
$stmt = $this->getCon()->geprepare($query);
$stmt->execute($paramArray);
$stmt->setFetchMode($fetchType);// $stmt->setFetchMode(PDO::FETCH_ASSOC);
$result = $stmt->fetch();
return $result;
}
}
?>