sintonia/airtime_mvc/application/common/Database.php

28 lines
799 B
PHP
Raw Normal View History

<?php
class Application_Common_Database
{
2012-09-05 23:44:09 +02:00
public static function prepareAndExecute($sql, $paramValueMap, $type='all')
{
$con = Propel::getConnection();
$stmt = $con->prepare($sql);
foreach ($paramValueMap as $param => $v) {
$stmt->bindValue($param, $v);
}
$rows = array();
if ($stmt->execute()) {
if ($type == 'single') {
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
2012-09-05 23:44:09 +02:00
} elseif ($type == 'column'){
$rows = $stmt->fetchColumn();
} else {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
return $rows;
}
2012-09-05 23:44:09 +02:00
}