Format code using php-cs-fixer
This commit is contained in:
parent
43d7dc92cd
commit
d52c6184b9
352 changed files with 17473 additions and 17041 deletions
|
@ -1,18 +1,20 @@
|
|||
<?php
|
||||
|
||||
class Application_Common_Database
|
||||
{
|
||||
const SINGLE = 'single';
|
||||
const COLUMN = 'column';
|
||||
const ALL = 'all';
|
||||
const EXECUTE = 'execute';
|
||||
const ROW_COUNT = 'row_count';
|
||||
public const SINGLE = 'single';
|
||||
public const COLUMN = 'column';
|
||||
public const ALL = 'all';
|
||||
public const EXECUTE = 'execute';
|
||||
public const ROW_COUNT = 'row_count';
|
||||
|
||||
public static function prepareAndExecute($sql,
|
||||
array $paramValueMap = array(),
|
||||
$type=self::ALL,
|
||||
$fetchType=PDO::FETCH_ASSOC,
|
||||
$con=null)
|
||||
{
|
||||
public static function prepareAndExecute(
|
||||
$sql,
|
||||
array $paramValueMap = [],
|
||||
$type = self::ALL,
|
||||
$fetchType = PDO::FETCH_ASSOC,
|
||||
$con = null
|
||||
) {
|
||||
if (is_null($con)) {
|
||||
$con = Propel::getConnection();
|
||||
}
|
||||
|
@ -20,51 +22,64 @@ class Application_Common_Database
|
|||
foreach ($paramValueMap as $param => $v) {
|
||||
$stmt->bindValue($param, $v);
|
||||
}
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
if ($stmt->execute()) {
|
||||
if ($type == self::SINGLE) {
|
||||
$rows = $stmt->fetch($fetchType);
|
||||
} else if ($type == self::COLUMN){
|
||||
} elseif ($type == self::COLUMN) {
|
||||
$rows = $stmt->fetchColumn();
|
||||
} else if ($type == self::ALL) {
|
||||
} elseif ($type == self::ALL) {
|
||||
$rows = $stmt->fetchAll($fetchType);
|
||||
} else if ($type == self::EXECUTE) {
|
||||
} elseif ($type == self::EXECUTE) {
|
||||
$rows = null;
|
||||
} else if ($type == self::ROW_COUNT) {
|
||||
} elseif ($type == self::ROW_COUNT) {
|
||||
$rows = $stmt->rowCount();
|
||||
} else {
|
||||
$msg = "bad type passed: type($type)";
|
||||
throw new Exception("Error: $msg");
|
||||
$msg = "bad type passed: type({$type})";
|
||||
|
||||
throw new Exception("Error: {$msg}");
|
||||
}
|
||||
} else {
|
||||
$msg = implode(',', $stmt->errorInfo());
|
||||
throw new Exception("Error: $msg");
|
||||
|
||||
throw new Exception("Error: {$msg}");
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/*
|
||||
Wrapper around prepareAndExecute that allows you to use multipe :xx's
|
||||
in one query. Transforms $sql to :xx1, :xx2, ....
|
||||
*/
|
||||
public static function smartPrepareAndExecute($sql, array $params,
|
||||
$type='all', $fetchType=PDO::FETCH_ASSOC)
|
||||
{
|
||||
$new_params = array();
|
||||
$new_sql = $sql;
|
||||
public static function smartPrepareAndExecute(
|
||||
$sql,
|
||||
array $params,
|
||||
$type = 'all',
|
||||
$fetchType = PDO::FETCH_ASSOC
|
||||
) {
|
||||
$new_params = [];
|
||||
$new_sql = $sql;
|
||||
foreach ($params as $k => $v) {
|
||||
$matches_count = substr_count($sql, $k);
|
||||
if ($matches_count == 0) {
|
||||
throw new Exception("Argument $k is not inside $sql");
|
||||
} elseif ($matches_count == 1) {
|
||||
throw new Exception("Argument {$k} is not inside {$sql}");
|
||||
}
|
||||
if ($matches_count == 1) {
|
||||
$new_params[$k] = $new_params[$v];
|
||||
} else {
|
||||
foreach ( range(1,$matches_count) as $i ) {
|
||||
preg_replace( "/$k(\D)/", "{$k}{$i}${1}", $sql, 1);
|
||||
$new_params[ $k.$i ] = $v;
|
||||
foreach (range(1, $matches_count) as $i) {
|
||||
preg_replace("/{$k}(\D)/", "{$k}{$i}${1}", $sql, 1);
|
||||
$new_params[$k . $i] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Application_Common_Database::prepareAndExecute( $new_sql,
|
||||
$new_params, $type, $fetchType);
|
||||
|
||||
return Application_Common_Database::prepareAndExecute(
|
||||
$new_sql,
|
||||
$new_params,
|
||||
$type,
|
||||
$fetchType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue