Asf_Db_AbstractAdapter::getCount

获取记录集的总数量


Description

public int getCount([string $sql_where = '' [, array $bind_value = array()]])

Parameters

sql_where

where部分的条件语句

bind_value

把一个值绑定到一个参数

Return Values

返回正整数

Examples

Connect MySQL Database

<?php
$configs = array(
    'dsn' => array('host' => '127.0.0.1', 'dbname' => 'test', 'port' => 6666),
    'username' => 'test',
    'password' => 'AbcdefRDvgedf',
);

$mysql = new Asf_Db_Adapter_Mysql($configs);
$mysql->setTable('test1');

Example #1

<?php
// [SQL] SELECT count(*) cnt FROM `test1`
var_dump($mysql->getCount(1));

Example #2

<?php
// [SQL] SELECT count(*) cnt FROM `test1` WHERE status = ?  [VALUE] 0
$sql_where = "status = ?";
var_dump($mysql->getCount($sql_where, array(0)));

Example #3

<?php
//  SELECT count(*) asf asf_cnt FROM `table_name` WHERE id > 10 and status in (0, 1)

$sql_where = "id > 10 and status in (0, 1)";
var_dump($mysql->getCount($sql_where));

Example #4

<?php
// [SQL] SELECT count(*) as asf_cnt FROM `table_name` WHERE id=? and status != ?   [VALUE] a:2:{i:0;s:3:"589";i:1;i:-1;} 

$id = 589; $status = -1;
Asf\Db::getCount('id=? and status != ?', array($id, $status))