2011-02-24 Miguel de Dios <miguel.dedios@artica.es>

* include/db/postgresql.php, include/db/mysql.php,include/functions_db.php:
	created the function "postgresql_get_db_row" in to the engines mysql and
	postgreSQL.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4017 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-02-24 10:23:42 +00:00
parent d2c6861d4d
commit a8872cfea6
4 changed files with 105 additions and 24 deletions

View File

@ -1,3 +1,9 @@
2011-02-24 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php,include/functions_db.php:
created the function "postgresql_get_db_row" in to the engines mysql and
postgreSQL.
2011-02-24 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:

View File

@ -115,6 +115,50 @@ function mysql_get_db_value ($field, $table, $field_search = 1, $condition = 1,
return $result[0][$field];
}
/**
* Get the first row of a database query into a table.
*
* The SQL statement executed would be something like:
* "SELECT (*||$fields) FROM $table WHERE $field_search = $condition"
*
* @param string Table to get the row
* @param string Field to filter elements
* @param string Condition the field must have.
* @param mixed Fields to select (array or string or false/empty for *)
*
* @return mixed The first row of a database query or false.
*/
function mysql_get_db_row ($table, $field_search, $condition, $fields = false) {
if (empty ($fields)) {
$fields = '*';
}
else {
if (is_array ($fields))
$fields = implode (',', $fields);
else if (! is_string ($fields))
return false;
}
if (is_int ($condition)) {
$sql = sprintf ("SELECT %s FROM `%s` WHERE `%s` = %d LIMIT 1",
$fields, $table, $field_search, $condition);
}
else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT %s FROM `%s` WHERE `%s` = %f LIMIT 1",
$fields, $table, $field_search, $condition);
}
else {
$sql = sprintf ("SELECT %s FROM `%s` WHERE `%s` = '%s' LIMIT 1",
$fields, $table, $field_search, $condition);
}
$result = get_db_all_rows_sql ($sql);
if ($result === false)
return false;
return $result[0];
}
/**
* Get all the rows in a table of the database.
*

View File

@ -78,6 +78,50 @@ function postgresql_get_db_value ($field, $table, $field_search = 1, $condition
}
}
/**
* Get the first row of a database query into a table.
*
* The SQL statement executed would be something like:
* "SELECT (*||$fields) FROM $table WHERE $field_search = $condition"
*
* @param string Table to get the row
* @param string Field to filter elements
* @param string Condition the field must have.
* @param mixed Fields to select (array or string or false/empty for *)
*
* @return mixed The first row of a database query or false.
*/
function postgresql_get_db_row ($table, $field_search, $condition, $fields = false) {
if (empty ($fields)) {
$fields = '*';
}
else {
if (is_array ($fields))
$fields = implode (',', $fields);
else if (! is_string ($fields))
return false;
}
if (is_int ($condition)) {
$sql = sprintf ('SELECT %s FROM "%s" WHERE \'%s\' = %d LIMIT 1',
$fields, $table, $field_search, $condition);
}
else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT %s FROM \"%s\" WHERE '%s' = %f LIMIT 1",
$fields, $table, $field_search, $condition);
}
else {
$sql = sprintf ("SELECT %s FROM \"%s\" WHERE '%s' = '%s' LIMIT 1",
$fields, $table, $field_search, $condition);
}
$result = get_db_all_rows_sql ($sql);
if ($result === false)
return false;
return $result[0];
}
function postgresql_get_db_all_rows_sql ($sql, $search_history_db = false, $cache = true) {
global $config;

View File

@ -69,6 +69,7 @@ function check_login () {
include("general/noaccess.php");
exit;
}
if ((isset($_SESSION["id_usuario"])) AND ($_SESSION["id_usuario"] != "")) {
if (is_user ($_SESSION["id_usuario"])) {
return 0;
@ -86,6 +87,7 @@ function check_login () {
}
}
}
pandora_audit("No session", "Trying to access without a valid session", "N/A");
include ($config["homedir"]."/general/noaccess.php");
exit;
@ -2162,31 +2164,16 @@ function get_db_row_sql ($sql, $search_history_db = false) {
* @return mixed The first row of a database query or false.
*/
function get_db_row ($table, $field_search, $condition, $fields = false) {
if (empty ($fields)) {
$fields = '*';
} else {
if (is_array ($fields))
$fields = implode (',', $fields);
else if (! is_string ($fields))
return false;
global $config;
switch ($config["dbtype"]) {
case "mysql":
return mysql_get_db_row($table, $field_search, $condition, $fields);
break;
case "postgresql":
return postgresql_get_db_row($table, $field_search, $condition, $fields);
break;
}
if (is_int ($condition)) {
$sql = sprintf ("SELECT %s FROM `%s` WHERE `%s` = %d LIMIT 1",
$fields, $table, $field_search, $condition);
} else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT %s FROM `%s` WHERE `%s` = %f LIMIT 1",
$fields, $table, $field_search, $condition);
} else {
$sql = sprintf ("SELECT %s FROM `%s` WHERE `%s` = '%s' LIMIT 1",
$fields, $table, $field_search, $condition);
}
$result = get_db_all_rows_sql ($sql);
if ($result === false)
return false;
return $result[0];
}
/**