Improved the functions that return a value

This commit is contained in:
Alejandro Gallardo Escobar 2015-05-18 19:05:22 +02:00
parent f7867e3ce0
commit b8f2daf6fa
3 changed files with 55 additions and 46 deletions

View File

@ -120,11 +120,13 @@ function mysql_db_get_value ($field, $table, $field_search = 1, $condition = 1,
if ($result === false) if ($result === false)
return false; return false;
if ($field[0] == '`') $row = array_shift($result);
$field = str_replace ('`', '', $field); $value = array_shift($row);
if ($value === null)
return false;
return $result[0][$field]; return $value;
} }
/** /**
@ -412,9 +414,13 @@ function mysql_db_get_value_filter ($field, $table, $filter, $where_join = 'AND'
if ($result === false) if ($result === false)
return false; return false;
$fieldClean = str_replace('`', '', $field); $row = array_shift($result);
$value = array_shift($row);
return $result[0][$fieldClean]; if ($value === null)
return false;
return $value;
} }
/** /**
@ -610,8 +616,13 @@ function mysql_db_get_value_sql($sql, $dbconnection = false) {
if ($result === false) if ($result === false)
return false; return false;
foreach ($result[0] as $f) $row = array_shift($result);
return $f; $value = array_shift($row);
if ($value === null)
return false;
return $value;
} }
/** /**

View File

@ -90,15 +90,13 @@ function oracle_db_get_value ($field, $table, $field_search = 1, $condition = 1,
if ($result === false) if ($result === false)
return false; return false;
if ($field[0] == '`') $row = array_shift($result);
$field = str_replace ('`', '', $field); $value = array_shift($row);
if (!isset($result[0][$field])) { if ($value === null)
return reset($result[0]); return false;
}
else { return $value;
return $result[0][$field];
}
} }
/** /**
@ -499,9 +497,13 @@ function oracle_db_get_value_filter ($field, $table, $filter, $where_join = 'AND
if ($result === false) if ($result === false)
return false; return false;
$fieldClean = str_replace('`', '', $field); $row = array_shift($result);
$value = array_shift($row);
return $result[0][$fieldClean]; if ($value === null)
return false;
return $value;
} }
/** /**
@ -870,8 +872,13 @@ function oracle_db_get_value_sql($sql, $dbconnection = false) {
if ($result === false) if ($result === false)
return false; return false;
foreach ($result[0] as $f) $row = array_shift($result);
return $f; $value = array_shift($row);
if ($value === null)
return false;
return $value;
} }
/** /**

View File

@ -72,15 +72,13 @@ function postgresql_db_get_value ($field, $table, $field_search = 1, $condition
if ($result === false) if ($result === false)
return false; return false;
if ($field[0] == '`') $row = array_shift($result);
$field = str_replace ('`', '', $field); $value = array_shift($row);
if (!isset($result[0][$field])) { if ($value === null)
return reset($result[0]); return false;
}
else { return $value;
return $result[0][$field];
}
} }
/** /**
@ -416,11 +414,6 @@ function postgresql_db_get_value_filter ($field, $table, $filter, $where_join =
if (strstr($field, "(") === false) { if (strstr($field, "(") === false) {
//It is a field. //It is a field.
$field = '"' . $field . '"'; $field = '"' . $field . '"';
$is_a_function = false;
}
else {
//It is a function.
$is_a_function = true;
} }
$sql = sprintf ("SELECT %s FROM \"%s\" WHERE %s LIMIT 1", $sql = sprintf ("SELECT %s FROM \"%s\" WHERE %s LIMIT 1",
@ -429,20 +422,13 @@ function postgresql_db_get_value_filter ($field, $table, $filter, $where_join =
$result = db_get_all_rows_sql ($sql, $search_history_db); $result = db_get_all_rows_sql ($sql, $search_history_db);
if ($result === false) $row = array_shift($result);
$value = array_shift($row);
if ($value === null)
return false; return false;
if (!$is_a_function) { return $value;
$fieldClean = str_replace('"', '', $field);
$fieldClean = str_replace('`', '', $fieldClean);
}
else {
//Extract the name of function.
$temp = explode('(', $field);
$fieldClean = strtolower(trim($temp[0]));
}
return $result[0][$fieldClean];
} }
/** /**
@ -634,8 +620,13 @@ function postgresql_db_get_value_sql($sql, $dbconnection = false) {
if ($result === false) if ($result === false)
return false; return false;
foreach ($result[0] as $f) $row = array_shift($result);
return $f; $value = array_shift($row);
if ($value === null)
return false;
return $value;
} }
/** /**