Login   Register  
PHP Classes
elePHPant
Icontem

File: pi_lib/plugins/mysql.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/mysql.php  >  Download  
File: pi_lib/plugins/mysql.php
Role: Auxiliary script
Content type: text/plain
Description: MySQL plugin
Class: Paginator Iterator
Iterate over listings split in page using Smarty
Author: By
Last change:
Date: 2008-08-07 06:35
Size: 783 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_mysql_ds(&$db$sql$offset$limit, &$pi)
{
    try    
    {
        
$dataSource=array();
        
$sql=str_replace(":OFFSET"$offset$sql);
        
$sql=str_replace(":LIMIT"$limit$sql);
        if(
$result=mysql_query($sql$db))
        {
            while(
$row=mysql_fetch_assoc($result))
                
$dataSource[]=$row;
            
mysql_free_result($result);
        }

        return 
$dataSource;
    }
    catch(
Exception $e) {
        throw 
$e;
    }
}

/**
*    Must to return a number
*/
function pi_mysql_numrows(&$db$sql, &$pi)
{
    if(
$result=mysql_query($sql$db))
    {
        
$row=mysql_fetch_row($result);
        return 
$row[0];
    }

    return 
0;
}

?>