INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / RSS / GPG

CodeIgniter 1.7.2 SQL_CALC_FOUND_ROWS patch

№ 1754 В разделе Programming от 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');
$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();

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:

    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 ‘;

    $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 *



Fortune cookie: Hear about... the girl who called her boyfriend Amaretto, 'cause he was such a sweet liquor?