From 7ab5dfb7065dc6850494fced8a47d23fff20e233 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Tue, 26 Feb 2019 11:03:30 +0900 Subject: [PATCH] Update database.php --- system/database.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/system/database.php b/system/database.php index e99519f..384b259 100644 --- a/system/database.php +++ b/system/database.php @@ -79,25 +79,25 @@ if(!function_exists("get_dbc_object")) { } } -// 2018-08-19: support lower php version (not supported anonymous function) -if(!function_exists("compare_db_key_length")) { - function compare_db_key_length($a, $b) { - return strlen($b) - strlen($a); +if(!function_exists("get_db_binded_param")) { + function get_db_binded_param($expression, $bind) { + foreach($bind as $k=>$v) { + if($expression == (":" . $k)) { + $expression = sprintf("'%s'", make_safe_argument($v)); + } + } + + return $expression; } } if(!function_exists("get_db_binded_sql")) { function get_db_binded_sql($sql, $bind) { - if(count($bind) > 0) { - $bind_keys = array_keys($bind); - - // 2018-08-19: support lower php version (not supported anonymous function) - usort($bind_keys, "compare_db_key_length"); - - foreach($bind_keys as $k) { - $sql = str_replace(":" . $k, "'" . make_safe_argument($bind[$k]) . "'", $sql); - } + $d = explode(" ", $sql); + foreach($d as $k=>$v) { + $d[$k] = get_db_binded_param($v, $bind); } + $sql = implode(" ", $d); return $sql; }