Можно ли вызвать свою функцию в конце работы объекта? По аналогии с деструктором?
вот сам код класса
class DB
{
private $bValue;
private $db;
private $db_host = "localhost";
private $db_name = "";
private $db_user = "";
private $db_pass = "";
public function __construct(){
$this->str = "";
$this->connectDb($this->db_name, $this->db_user, $this->db_pass, $this->db_host);
}
public function __destruct(){
$this->db = null;
}
public function sql($sql){
$this->str .= $sql;
return $this;
}
public function select($select){
$this->str .= 'SELECT SQL_CALC_FOUND_ROWS '.$select;
return $this;
}
public function from($from){
$this->str .= ' FROM '.$from;
return $this;
}
public function where($where){
$this->str .= ' WHERE '.$where;
return $this;
}
public function andwhere($andwhere){
$this->str .= ' AND '.$andwhere;
return $this;
}
public function orderBy($orderby){
$this->str .= ' ORDER BY '.$orderby;
return $this;
}
public function limit($limit){
$this->str .= ' LIMIT '.$limit;
return $this;
}
public function paginate($per_page){
$this->per_page = $per_page;
$this->cur_page = isset($_REQUEST['page']) ? ((int) $_REQUEST['page']) : 1;
$this->start = (int)(($this->cur_page - 1) * $this->per_page);
$this->str .= ' LIMIT :start, :per_page';
$this->bValue[] = array(':per_page', $this->per_page, PDO::PARAM_INT);
$this->bValue[] = array(':start', $this->start, PDO::PARAM_INT);
return $this;
}
public function bindValue($value1, $value2, $value3){
$this->bValue[] = array($value1, $value2, $value3);
return $this;
}
public function start(){
$sth = $this->db->prepare($this->str);
if($this->bValue)
{
foreach($this->bValue as $k)
{
$sth->bindValue($k[0], $k[1], $k[2]);
}
}
$sth->execute();
$this->rows = $this->db->query("SELECT FOUND_ROWS()")->fetchColumn(0);
return $this->result = $sth;
}
public function connectdb($db_name, $db_user, $db_pass, $db_host = "localhost"){
try {
$this->db = new \pdo("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
} catch (\pdoexception $e) {
echo "database error: " . $e->getmessage();
die();
}
$this->db->query('set names utf8');
return $this;
}
}
вызов такой
$DB = new DB();
$news = $DB->select('*')->from('news')->orderBy('date')->paginate(9)->start();
Хочу избавиться от start() в конце и сделать чтоб она запускалась всегда и без ее объяления