Update database.php
This commit is contained in:
parent
e1bae93666
commit
e74ea366e4
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file database.php
|
||||
* @date 2018-01-01
|
||||
* @author Go Namhyeon <gnh1201@gmail.com>
|
||||
* @brief Database module for ReasonableFramework
|
||||
*/
|
||||
|
||||
if(!function_exists("get_db_connect")) {
|
||||
function get_db_connect() {
|
||||
global $config;
|
||||
|
@ -164,8 +157,8 @@ if(!function_exists("exec_db_fetch_all")) {
|
|||
}
|
||||
|
||||
if(!function_exists("exec_db_fetch")) {
|
||||
function exec_db_fetch($sql, $bind=array(), $bind_limit=true) {
|
||||
$row = NULL;
|
||||
function exec_db_fetch($sql, $bind=array(), $start=0, $bind_limit=false) {
|
||||
$fetched = NULL;
|
||||
$rows = array();
|
||||
|
||||
if($bind_limit == true) {
|
||||
|
@ -173,62 +166,19 @@ if(!function_exists("exec_db_fetch")) {
|
|||
}
|
||||
|
||||
$rows = exec_db_fetch_all($sql, $bind);
|
||||
if(count($rows) > 0) {
|
||||
$row = $rows[0];
|
||||
}
|
||||
if(count($rows) > $start) {
|
||||
$idx = 0;
|
||||
foreach($rows as $row) {
|
||||
if($idx >= $start) {
|
||||
$fetched = $row;
|
||||
break;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
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}";
|
||||
$idx++;
|
||||
}
|
||||
}
|
||||
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);
|
||||
return $fetched;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user