CC-4345: Prepared statements - part 1

-added extra parameter to prepareAndExecute()
This commit is contained in:
denise 2012-09-05 17:52:53 -04:00
parent 0ae1b9fea6
commit 26c2c2c0d1
1 changed files with 4 additions and 5 deletions

View File

@ -1,9 +1,8 @@
<?php
class Application_Common_Database
{
public static function prepareAndExecute($sql, $paramValueMap, $type='all', $fetchType=PDO::FETCH_ASSOC){
public static function prepareAndExecute($sql, $paramValueMap, $type='all')
{
$con = Propel::getConnection();
$stmt = $con->prepare($sql);
foreach ($paramValueMap as $param => $v) {
@ -12,11 +11,11 @@ class Application_Common_Database
$rows = array();
if ($stmt->execute()) {
if ($type == 'single') {
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
} elseif ($type == 'column'){
$rows = $stmt->fetch($fetchType);
} else if ($type == 'column'){
$rows = $stmt->fetchColumn();
} else {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rows = $stmt->fetchAll($fetchType);
}
} else {
$msg = implode(',', $stmt->errorInfo());