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:
mdtrooper 2011-02-24 09:40:14 +00:00
parent bc0dfe8874
commit 81e7fd5287
5 changed files with 93 additions and 23 deletions

View File

@ -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> 2011-02-23 Ramon Novoa <rnovoa@artica.es>
* DEBIAN/control, DEBIAN/postinst, * DEBIAN/control, DEBIAN/postinst,

View File

@ -80,6 +80,41 @@ function mysql_get_db_all_rows_sql ($sql, $search_history_db = false, $cache = t
return false; 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. * Get all the rows in a table of the database.
* *

View File

@ -39,6 +39,45 @@ function postgresql_connect_db($host = null, $db = null, $user = null, $pass = n
return $config['dbconnection']; 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) { function postgresql_get_db_all_rows_sql ($sql, $search_history_db = false, $cache = true) {
global $config; global $config;

View File

@ -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. * @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) { function get_db_value($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) {
if (is_int ($condition)) { global $config;
$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) switch ($config["dbtype"]) {
return false; case "mysql":
return mysql_get_db_value($field, $table, $field_search, $condition, $search_history_db);
if ($field[0] == '`') break;
$field = str_replace ('`', '', $field); case "postgresql":
return postgresql_get_db_value($field, $table, $field_search, $condition, $search_history_db);
break;
return $result[0][$field]; }
} }
/** /**

View File

@ -229,7 +229,8 @@ if ($config["pure"] == 0) {
echo '</div><div id="page"><div id="menu">'; echo '</div><div id="page"><div id="menu">';
require ("general/main_menu.php"); require ("general/main_menu.php");
echo '</div>'; echo '</div>';
} else { }
else {
echo '<div id="main_pure">'; echo '<div id="main_pure">';
} }