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