Login   Register  
PHP Classes
elePHPant
Icontem

File: pi_lib/plugins/pdo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Anderson A. Meggiolaro  >  Paginator Iterator  >  pi_lib/plugins/pdo.php  >  Download  
File: pi_lib/plugins/pdo.php
Role: Auxiliary script
Content type: text/plain
Description: PDO plugin
Class: Paginator Iterator
Iterate over listings split in page using Smarty
Author: By
Last change:
Date: 2008-08-07 06:33
Size: 661 bytes
 

Contents

Class file image Download
<?php

/**
*    Must to return an array like this:
*    array(
*        array('id'=>1, 'name'=>'a'),
*        array('id'=>2, 'name'=>'b'),
*        array('id'=>23, 'name'=>'')
*    );
*/
function pi_pdo_ds(PDO &$db$sql$offset$limit, &$pi)
{
    try    {
        
$dataSource=array();

        
$sql=str_replace(":OFFSET"$offset$sql);
        
$sql=str_replace(":LIMIT"$limit$sql);
        
        
$r=$db->query($sql);
        if(
$r!==false)
            
$dataSource=$r->fetchAll(PDO::FETCH_ASSOC);
        return 
$dataSource;
    }
    catch(
Exception $e) {
        throw 
$e;
    }
}

/**
*    Must to return a number
*/
function pi_pdo_numrows(PDO &$db$sql, &$pi)
{
    return 
$db->query($sql)->fetchColumn(0);
}

?>