Skip navigation.

极湖

无不用其“极”

让 Zend_Db 支持 MySQL 的 SQL_CALC_FOUND_ROWS

, ,

修改 Zend/Db/Select.php, 增加以下代码

const FOUND_ROWS     = 'foundrows'; 
const SQL_FOUND_ROWS = 'SQL_CALC_FOUND_ROWS'; 

protected static $_partsInit = array(
    self::FOUND_ROWS   => false,  
    ... ...
);

/**
 * Makes the query SELECT SQL_CALC_FOUND_ROWS.  
 *
 * @param bool $flag Whether or not add SQL_CALC_FOUND_ROWS to SELECT.
 * @return Zend_Db_Select This Zend_Db_Select object.
 */
public function foundRows($flag = true)
{
    $this->_parts[self::FOUND_ROWS] = (bool) $flag;
    return $this;
}

/**
 * Render FOUND_ROWS clause  
 *
 * @param string   $sql SQL query
 * @return string
 */
protected function _renderFoundRows($sql)
{
    if ($this->_parts[self::FOUND_ROWS]) {
        $sql .= ' ' . self::SQL_FOUND_ROWS;
    }

    return $sql;
}


以上代码的具体位置不再详述。

调用方法如下:

$select = $db->select()->foundRows()->from(
  ... ...
)->where(
  ... ...
);

$data = $db->fetchAll($select);

$stmt = $db->query("SELECT FOUND_ROWS() as cnt");
list($rec) = $stmt->fetchAll();
$count = $rec['cnt'];

三个 JavaScript 工具 + 批处理ExtJS 2.x 的多行工具条实现

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31