<?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);
}
?>
|