PHP Classes

File: pi_lib/plugins/mysqli.php

Recommend this page to a friend!
  Classes of Anderson A. Meggiolaro   Paginator Iterator   pi_lib/plugins/mysqli.php   Download  
File: pi_lib/plugins/mysqli.php
Role: Auxiliary script
Content type: text/plain
Description: MySQLi plugin
Class: Paginator Iterator
Iterate over listings split in page using Smarty
Author: By
Last change:
Date: 15 years ago
Size: 757 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_mysqli_ds(&$db, $sql, $offset, $limit, &$pi)
{
    try
    {
       
$dataSource=array();
       
$sql=str_replace(":OFFSET", $offset, $sql);
       
$sql=str_replace(":LIMIT", $limit, $sql);
        if(
$result=$db->query($sql))
        {
            while(
$row=$result->fetch_assoc())
               
$dataSource[]=$row;
           
$result->close();
        }

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

/**
* Must to return a number
*/
function pi_mysqli_numrows(&$db, $sql, &$pi)
{
    if(
$result=$db->query($sql))
    {
       
$row=$result->fetch_row();
        return
$row[0];
    }
   
    return
0;
}

?>