should constants instead of literals - only in function for now...

This commit is contained in:
Martin Konecny 2013-05-09 13:28:26 -04:00
parent 17c3eb1407
commit 92c7c9c951
1 changed files with 9 additions and 4 deletions

View File

@ -1,6 +1,11 @@
<?php <?php
class Application_Common_Database class Application_Common_Database
{ {
const SINGLE = 'single';
const COLUMN = 'column';
const ALL = 'all';
const EXECUTE = 'execute';
public static function prepareAndExecute($sql, array $paramValueMap, public static function prepareAndExecute($sql, array $paramValueMap,
$type='all', $fetchType=PDO::FETCH_ASSOC, $con=null) $type='all', $fetchType=PDO::FETCH_ASSOC, $con=null)
{ {
@ -13,13 +18,13 @@ class Application_Common_Database
} }
$rows = array(); $rows = array();
if ($stmt->execute()) { if ($stmt->execute()) {
if ($type == 'single') { if ($type == self::SINGLE) {
$rows = $stmt->fetch($fetchType); $rows = $stmt->fetch($fetchType);
} else if ($type == 'column'){ } else if ($type == self::COLUMN){
$rows = $stmt->fetchColumn(); $rows = $stmt->fetchColumn();
} else if ($type == 'all') { } else if ($type == self::ALL) {
$rows = $stmt->fetchAll($fetchType); $rows = $stmt->fetchAll($fetchType);
} else if ($type == 'execute') { } else if ($type == self::EXECUTE) {
$rows = null; $rows = null;
} else { } else {
$msg = "bad type passed: type($type)"; $msg = "bad type passed: type($type)";