RedBeanPHP\Repository::count PHP Method

count() public method

This method accepts a second argument to modify the count-query. A third argument can be used to provide bindings for the SQL snippet.
public count ( string $type, string $addSQL = '', array $bindings = [] ) : integer
$type string type of bean we are looking for
$addSQL string additional SQL snippet
$bindings array parameters to bind to SQL
return integer
    public function count($type, $addSQL = '', $bindings = array())
    {
        $type = AQueryWriter::camelsSnake($type);
        if (count(explode('_', $type)) > 2) {
            throw new RedException('Invalid type for count.');
        }
        try {
            return (int) $this->writer->queryRecordCount($type, array(), $addSQL, $bindings);
        } catch (SQLException $exception) {
            if (!$this->writer->sqlStateIn($exception->getSQLState(), array(QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN))) {
                throw $exception;
            }
        }
        return 0;
    }

Usage Example

Beispiel #1
0
 /**
  * Counts the number of beans of type $type.
  * This method accepts a second argument to modify the count-query.
  * A third argument can be used to provide bindings for the SQL snippet.
  *
  * @param string $type     type of bean we are looking for
  * @param string $addSQL   additional SQL snippet
  * @param array  $bindings parameters to bind to SQL
  *
  * @return integer
  */
 public function count($type, $addSQL = '', $bindings = array())
 {
     return $this->repository->count($type, $addSQL, $bindings);
 }