From 8502db45ce2e1244bffc6ab83a75d5be11e64aaf Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 26 Mar 2018 11:52:49 +0900 Subject: [PATCH] Update database.php --- system/database.php | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/system/database.php b/system/database.php index bdc16e1..a09fa89 100644 --- a/system/database.php +++ b/system/database.php @@ -1,4 +1,11 @@ + * @brief Database module for ReasonableFramework + */ + if(!function_exists("get_db_connect")) { function get_db_connect() { global $config; @@ -182,5 +189,56 @@ if(!function_exists("exec_db_fetch")) { } } +if(!function_exists("get_page_range")) { + function get_page_range($page=1, $limit=0) { + $append_sql = ""; + + if($limit > 0) { + $record_start = ($page - 1) * $limit; + $record_end = $record_start + $limit - 1; + $append_sql .= " limit $record_start, $record_end"; + } + + return $append_sql; + } +} + +if(!function_exists("get_bind_to_sql_where")) { + // warning: variable k is not protected. do not use variable k and external variable without filter + function get_bind_to_sql_where($bind, $excludes=array()) { + $sql_where = ""; + foreach($bind as $k=>$v) { + if(!in_array($k, $excludes)) { + $sql_where .= " and {$k} = :{$k}"; + } + } + return $sql_where; + } +} + +if(!function_exists("get_bind_to_sql_update_set")) { + // warning: variable k is not protected. do not use variable k and external variable without filter + function get_bind_to_sql_update_set($bind, $excludes=array()) { + $sql_update_set = ""; + + $set_items = ""; + foreach($bind as $k=>$v) { + if(!in_array($k, $excludes)) { + $set_items[] = "{$k} = :{$k}"; + } + } + $sql_update_set = implode(", ", $set_items); + + return $sql_update_set; + } +} + +// alias sql_query from exec_db_query +if(!function_exists("sql_query")) { + function sql_query($sql, $bind=array()) { + return exec_db_query($sql, $bind); + } +} + // set global db connection variable $dbc = get_db_connect();