PHP Classes

File: src/query/CountQuery.php

Recommend this page to a friend!
  Classes of Vitaly   Queasy DB   src/query/CountQuery.php   Download  
File: src/query/CountQuery.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Queasy DB
Execute queries by accessing class variables
Author: By
Last change:
Date: 3 years ago
Size: 657 bytes
 

Contents

Class file image Download
<?php

namespace queasy\db\query;

class
CountQuery extends TableQuery
{
   
/**
     * Executes SQL query and returns all selected rows.
     *
     * @param array $params Query parameters
     *
     * @return int Count of records found
     *
     * @throws DbException On error
     */
   
public function run(array $params = array(), array $options = array())
    {
       
count($params)
            ?
$this->setSql(sprintf('SELECT count(*) FROM `%s` WHERE `%s` = :%2$s', $this->tableName(), key($params)))
            :
$this->setSql(sprintf('SELECT count(*) FROM `%s`', $this->tableName()));

        return
parent::run($params, $options);
    }
}