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) {
|
function get_items($orderby='id', $raw_values=false) {
|
||||||
global $db;
|
global $db;
|
||||||
try {
|
try {
|
||||||
$query = $db -> fpdo -> from('item')
|
$info = $db -> get_many('item', null, null, $orderby);
|
||||||
-> orderBy($orderby);
|
if (!is_array($info))
|
||||||
|
return;
|
||||||
|
if ($raw_values)
|
||||||
|
return $info;
|
||||||
|
|
||||||
$result = $query -> execute();
|
$items = array();
|
||||||
if ($result !== false) {
|
foreach ($info as $item)
|
||||||
$info = $result -> fetchAll();
|
$items[$item['id']] = $db -> format_row_info($item, array('date'));
|
||||||
if ($info === false)
|
return $items;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
Log :: error("Error retreiving items info from database : ".$e->getMessage());
|
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) {
|
function get_item($id, $raw_values=false) {
|
||||||
global $db;
|
global $db;
|
||||||
try {
|
try {
|
||||||
$query = $db -> fpdo -> from('item')
|
$info = $db -> get_one('item', array('id' => $id));
|
||||||
-> where('id', $id);
|
|
||||||
|
|
||||||
$result = $query -> execute();
|
if (!is_array($info))
|
||||||
if ($result !== false) {
|
return false;
|
||||||
$info = $result -> fetch();
|
|
||||||
if ($info === false)
|
|
||||||
return null;
|
|
||||||
if ($raw_values)
|
|
||||||
return $info;
|
|
||||||
|
|
||||||
return $db -> format_row_info($info, array('date'));
|
if ($raw_values)
|
||||||
}
|
return $info;
|
||||||
|
|
||||||
|
return $db -> format_row_info($info, array('date'));
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
Log :: error("Error retreiving item #$id info from database : ".$e->getMessage());
|
Log :: error("Error retreiving item #$id info from database : ".$e->getMessage());
|
||||||
|
|
Loading…
Reference in a new issue