example: add example of how to use Db get_one() & get_many() helpers
This commit is contained in:
parent
2584a59123
commit
becb9ad366
1 changed files with 16 additions and 26 deletions
|
@ -22,22 +22,16 @@ $db = new Db(
|
|||
function get_items($orderby='id', $raw_values=false) {
|
||||
global $db;
|
||||
try {
|
||||
$query = $db -> fpdo -> from('item')
|
||||
-> orderBy($orderby);
|
||||
$info = $db -> get_many('item', null, null, $orderby);
|
||||
if (!is_array($info))
|
||||
return;
|
||||
if ($raw_values)
|
||||
return $info;
|
||||
|
||||
$result = $query -> execute();
|
||||
if ($result !== false) {
|
||||
$info = $result -> fetchAll();
|
||||
if ($info === false)
|
||||
return null;
|
||||
if ($raw_values)
|
||||
return $info;
|
||||
|
||||
$items = array();
|
||||
foreach ($info as $item)
|
||||
$items[$item['id']] = $db -> format_row_info($item, array('date'));
|
||||
return $items;
|
||||
}
|
||||
$items = array();
|
||||
foreach ($info as $item)
|
||||
$items[$item['id']] = $db -> format_row_info($item, array('date'));
|
||||
return $items;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Log :: error("Error retreiving items info from database : ".$e->getMessage());
|
||||
|
@ -48,19 +42,15 @@ function get_items($orderby='id', $raw_values=false) {
|
|||
function get_item($id, $raw_values=false) {
|
||||
global $db;
|
||||
try {
|
||||
$query = $db -> fpdo -> from('item')
|
||||
-> where('id', $id);
|
||||
$info = $db -> get_one('item', array('id' => $id));
|
||||
|
||||
$result = $query -> execute();
|
||||
if ($result !== false) {
|
||||
$info = $result -> fetch();
|
||||
if ($info === false)
|
||||
return null;
|
||||
if ($raw_values)
|
||||
return $info;
|
||||
if (!is_array($info))
|
||||
return false;
|
||||
|
||||
return $db -> format_row_info($info, array('date'));
|
||||
}
|
||||
if ($raw_values)
|
||||
return $info;
|
||||
|
||||
return $db -> format_row_info($info, array('date'));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Log :: error("Error retreiving item #$id info from database : ".$e->getMessage());
|
||||
|
|
Loading…
Reference in a new issue