CC-4345: Prepared statements - part 1
-added extra parameter to prepareAndExecute()
This commit is contained in:
parent
0ae1b9fea6
commit
26c2c2c0d1
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
class Application_Common_Database
|
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();
|
$con = Propel::getConnection();
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
foreach ($paramValueMap as $param => $v) {
|
foreach ($paramValueMap as $param => $v) {
|
||||||
|
@ -12,11 +11,11 @@ class Application_Common_Database
|
||||||
$rows = array();
|
$rows = array();
|
||||||
if ($stmt->execute()) {
|
if ($stmt->execute()) {
|
||||||
if ($type == 'single') {
|
if ($type == 'single') {
|
||||||
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetch($fetchType);
|
||||||
} elseif ($type == 'column'){
|
} else if ($type == 'column'){
|
||||||
$rows = $stmt->fetchColumn();
|
$rows = $stmt->fetchColumn();
|
||||||
} else {
|
} else {
|
||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll($fetchType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$msg = implode(',', $stmt->errorInfo());
|
$msg = implode(',', $stmt->errorInfo());
|
||||||
|
|
Loading…
Reference in New Issue