2011-02-24 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php: create the function "get_db_value" for the engine mysql and postgreSQL. * index.php: cleaned source code. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4014 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
bc0dfe8874
commit
81e7fd5287
|
@ -1,3 +1,10 @@
|
|||
2011-02-24 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
|
||||
create the function "get_db_value" for the engine mysql and postgreSQL.
|
||||
|
||||
* index.php: cleaned source code.
|
||||
|
||||
2011-02-23 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* DEBIAN/control, DEBIAN/postinst,
|
||||
|
|
|
@ -80,6 +80,41 @@ function mysql_get_db_all_rows_sql ($sql, $search_history_db = false, $cache = t
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first value of the first row of a table in the database.
|
||||
*
|
||||
* @param string Field name to get
|
||||
* @param string Table to retrieve the data
|
||||
* @param string Field to filter elements
|
||||
* @param string Condition the field must have
|
||||
*
|
||||
* @return mixed Value of first column of the first row. False if there were no row.
|
||||
*/
|
||||
function mysql_get_db_value ($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) {
|
||||
if (is_int ($condition)) {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %d LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
else if (is_float ($condition) || is_double ($condition)) {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %f LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
else {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = '%s' LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
$result = get_db_all_rows_sql ($sql, $search_history_db);
|
||||
|
||||
if ($result === false)
|
||||
return false;
|
||||
|
||||
if ($field[0] == '`')
|
||||
$field = str_replace ('`', '', $field);
|
||||
|
||||
|
||||
return $result[0][$field];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the rows in a table of the database.
|
||||
*
|
||||
|
|
|
@ -39,6 +39,45 @@ function postgresql_connect_db($host = null, $db = null, $user = null, $pass = n
|
|||
return $config['dbconnection'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first value of the first row of a table in the database.
|
||||
*
|
||||
* @param string Field name to get
|
||||
* @param string Table to retrieve the data
|
||||
* @param string Field to filter elements
|
||||
* @param string Condition the field must have
|
||||
*
|
||||
* @return mixed Value of first column of the first row. False if there were no row.
|
||||
*/
|
||||
function postgresql_get_db_value ($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) {
|
||||
if (is_int ($condition)) {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %d LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
else if (is_float ($condition) || is_double ($condition)) {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %f LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
else {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = '%s' LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
$result = get_db_all_rows_sql ($sql, $search_history_db);
|
||||
|
||||
if ($result === false)
|
||||
return false;
|
||||
|
||||
if ($field[0] == '`')
|
||||
$field = str_replace ('`', '', $field);
|
||||
|
||||
if (!isset($result[0][$field])) {
|
||||
return reset($result[0]);
|
||||
}
|
||||
else {
|
||||
return $result[0][$field];
|
||||
}
|
||||
}
|
||||
|
||||
function postgresql_get_db_all_rows_sql ($sql, $search_history_db = false, $cache = true) {
|
||||
global $config;
|
||||
|
||||
|
|
|
@ -2053,29 +2053,17 @@ $sql_cache = array ('saved' => 0);
|
|||
*
|
||||
* @return mixed Value of first column of the first row. False if there were no row.
|
||||
*/
|
||||
function get_db_value ($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) {
|
||||
if (is_int ($condition)) {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %d LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
else if (is_float ($condition) || is_double ($condition)) {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %f LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
else {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = '%s' LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
$result = get_db_all_rows_sql ($sql, $search_history_db);
|
||||
function get_db_value($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) {
|
||||
global $config;
|
||||
|
||||
if ($result === false)
|
||||
return false;
|
||||
|
||||
if ($field[0] == '`')
|
||||
$field = str_replace ('`', '', $field);
|
||||
|
||||
|
||||
return $result[0][$field];
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
return mysql_get_db_value($field, $table, $field_search, $condition, $search_history_db);
|
||||
break;
|
||||
case "postgresql":
|
||||
return postgresql_get_db_value($field, $table, $field_search, $condition, $search_history_db);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -229,7 +229,8 @@ if ($config["pure"] == 0) {
|
|||
echo '</div><div id="page"><div id="menu">';
|
||||
require ("general/main_menu.php");
|
||||
echo '</div>';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
echo '<div id="main_pure">';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue