/**
  * Count all data
  *
  * @param callable|array|int $terms Use it if you want more terms
  * @param string             $column   Column to count
  * @param bool               $distinct Need a distinct count?
  * @return int
  */
 public function count($terms = null, $column = '', $distinct = false)
 {
     if (!$this->table) {
         return 0;
     }
     $query = $this->db->select()->count($column ?: '*', 'count', $distinct)->from($this->table);
     $this->normalizeTerms($query, $terms);
     return (int) $query->execute()->fetch()['count'];
 }
Example #2
0
 public function __construct($host, $db, $usr, $pwd, $opt = [])
 {
     $this->databaseName = $db;
     try {
         $dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8', $host, $db);
         parent::__construct($dsn, $usr, $pwd, $opt);
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
 }
 public function deleteResult(DeleteInterface $delete)
 {
     $result = null;
     $stmt = $delete->getStatement();
     try {
         $statement = $this->db->prepare($stmt);
         $result = $statement->execute($delete->getBindValues());
     } catch (PDOException $e) {
         $this->logger->error($delete->__toString());
         $this->logger->error($e->getMessage());
         return null;
     }
     return $result;
 }
Example #4
0
 /**
  * @return \PDOStatement
  */
 private function getStatement()
 {
     $sql = $this;
     return $this->dbh->prepare($sql);
 }