INT 21h

Hi, I am Vladimir Smagin, sysadmin. Telegram Email GPG

CodeIgniter 1.7.2 SQL_CALC_FOUND_ROWS patch

№ 1754 В разделе "Программирование" от November 24th, 2009,

CodeIgniter and SQL_CALC_FOUND_ROWS problem solved! I patched DB_active_rec.php today. Now I have ability to use SQL_CALC_FOUND_ROWS in my programs. If you use pages on your site, this function realy speed up it. With db->count_all* you send two big queries to DB, but with SQL_CALC_FOUND_ROWS solution you send only one big and one tiny.

$CI =& get_instance();
$CI->db->select('title, body');
$CI->db->SQL_CALC_FOUND_ROWS();
$CI->db->from('posts');
$query = $CI->db->get();
//All done, we got result. Now getting rows count
$count = $CI->db->query('SELECT FOUND_ROWS() as rowcount');
$count = $count->result();

patched_DB_active_rec.php.tar.bz

3 комментариев »

3 responses to “CodeIgniter 1.7.2 SQL_CALC_FOUND_ROWS patch”

  1. syk0saje says:

    hey. i’m trying to download the patch from this page but the link seems to be down: http://blindage.org/?p=1754

    is there anywhere else i could get it? thanks! 😀

  2. SV says:

    Great patch but I modified it a little bit to save ‘DISTINCT’ feature. Line 1502 should be changed from:
    $sql = ( ! $this->ar_distinct) ? ‘SELECT ‘ : ‘SELECT DISTINCT ‘;
    $sql = ( ! $this->ar_SQL_CALC_FOUND_ROWS) ? ‘SELECT ‘ : ‘SELECT SQL_CALC_FOUND_ROWS ‘;

    to:
    $sql = ( ! $this->ar_SQL_CALC_FOUND_ROWS) ? ‘SELECT ‘ : ‘SELECT SQL_CALC_FOUND_ROWS ‘;
    $sql .= ( ! $this->ar_distinct) ? ” : ‘DISTINCT ‘;

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Яндекс.Метрика