Open GoogleCodeExporter opened 8 years ago
{{{
/**
* Centralized creator of "WHERE" clause
*
* @param mixed $conditions to serialize/normalize, either array or string
* @param string $prefix to add to the where clause
*
* @return string the where clause string
* @since ADD MVC 0.0
*/
static function normalize_where($conditions, $prefix = "WHERE") {
$where_clause = "";
if (is_array($conditions)) {
$where_conditions = array();
$args = array();
foreach ($conditions as $field=>$value) {
if (strpos($field,':')) {
list($field,$operator) = explode(":",$field);
}
else {
$operator = "=";
}
if ($value === null) {
$where_conditions[] = static::db()->meta_quote($field)." IS NULL";
}
else {
$where_conditions[] = static::db()->meta_quote($field)."$operator".static::db()->quote($value);
}
}
if ($where_conditions) {
$where_clause = "$prefix ".implode(" AND ",$where_conditions);
}
}
else if (is_string($conditions)) {
# Make sure there's something
if (trim($conditions)) {
$where_clause = "$prefix ".$conditions;
}
else {
return false;
}
}
return " $where_clause ";
}
}}}
Original comment by albertdi...@gmail.com
on 10 Mar 2015 at 9:46
Question is, how compatible is this to different database systems?
Original comment by albertdi...@gmail.com
on 10 Mar 2015 at 9:47
Original issue reported on code.google.com by
albertdi...@gmail.com
on 10 Mar 2015 at 9:17