Merge pull request #18 from gnh1201/router

fix system/database
This commit is contained in:
Namhyeon Go 2018-12-29 11:52:23 +09:00 committed by GitHub
commit 88aa5342e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 19 deletions

View File

@ -15,7 +15,7 @@ if(!function_exists("exec_db_alt_callback")) {
if(loadHelper(sprintf("database.%s", $rule['driver']))) {
if(function_exists($rule['callback'])) {
if(is_array($params) && count($params) > 0) {
$result = call_user_func_array($rule['callback'], $params);
$result = call_user_func_array($rule['callback'], $params);
} else {
$result = call_user_func($rule['callback']);
}
@ -27,7 +27,7 @@ if(!function_exists("exec_db_alt_callback")) {
break;
}
}
return $result;
}
}
@ -53,9 +53,13 @@ if(!function_exists("get_db_alt_connect")) {
array(
"driver" => "oracle",
"callback" => "get_db_oracle_connect"
),
array(
"driver" => "pgsql",
"callback" => "get_db_pgsql_connect"
)
);
$conn = exec_db_alt_callback($rules);
return $conn;
@ -82,9 +86,13 @@ if(!function_exists("exec_db_alt_query")) {
array(
"driver" => "oracle",
"callback" => "exec_db_oracle_query"
),
array(
"driver" => "pgsql",
"callback" => "exec_db_pgsql_query"
)
);
$result = exec_db_alt_callback($rules, array($sql, $bind));
return $result;
@ -111,9 +119,13 @@ if(!function_exists("exec_db_alt_fetch_all")) {
array(
"driver" => "oracle",
"callback" => "exec_db_oracle_fetch_all"
)
),
array(
"driver" => "pgsql",
"callback" => "exec_db_pgsql_fetch_all"
)
);
$rows = exec_db_alt_callback($rules, array($sql, $bind));
return $rows;
@ -133,3 +145,17 @@ if(!function_exists("exec_db_alt_fetch")) {
return $fetched;
}
}
if(!function_exists("get_db_alt_last_id")) {
function get_db_alt_last_id($driver) {
$last_id = false;
if($driver == "mysql.imp") {
$last_id = @mysqli_insert_id();
} elseif($driver == "mysql.old") {
$last_id = @mysql_insert_id();
}
return $last_id;
}
}

View File

@ -38,10 +38,8 @@ if(!function_exists("get_db_connect")) {
$conn = get_db_connect($a, $b);
}
}
} else {
if(loadHelper("database.alt")) {
$conn = call_user_func("get_db_alt_connect", $db_driver);
}
} elseif(loadHelper("database.alt")) {
$conn = call_user_func("get_db_alt_connect", $db_driver);
}
return $conn;
@ -88,7 +86,7 @@ if(!function_exists("get_db_binded_sql")) {
$sql = str_replace(":" . $k, "'" . addslashes($bind[$k]) . "'", $sql);
}
}
return $sql;
}
}
@ -118,7 +116,19 @@ if(!function_exists("get_db_stmt")) {
if(!function_exists("get_db_last_id")) {
function get_db_last_id() {
return get_dbc_object()->lastInsertId();
$last_id = false;
$dbc = get_dbc_object();
$config = get_config();
$db_driver = get_value_in_array("db_driver", $config, "");
if(in_array($db_driver, array("mysql", "mysql.pdo"))) {
$last_id = $dbc->lastInsertId();
} elseif(loadHelper("database.dbt")) {
$last_id = call_user_func("get_db_alt_last_id", $db_driver);
}
return $last_id;
}
}
@ -459,7 +469,7 @@ if(!function_exists("get_timediff_on_query")) {
if(!function_exists("json_decode_to_assoc")) {
function json_decode_to_assoc($data) {
$result = array();
$func_rules = array(
"json_decode" => "Dose not exists json_decode function",
"json_last_error" => "Dose not exists json_last_error function",

View File

@ -80,7 +80,7 @@ if(!function_exists("read_requests")) {
if(!function_exists("get_requests")) {
function get_requests() {
$requests = get_scope("requests");
if(!is_array($requests)) {
set_scope("requests", read_requests());
}
@ -99,8 +99,8 @@ if(!function_exists("get_final_link")) {
$query_str = "";
$strings = explode("?", $url);
$pos = (count($strings) > 1) ? strlen($strings[0]) : -1;
$pos = (count($strings) > 1) ? strlen($strings[0]) : -1;
if($pos < 0) {
$base_url = $url;
} else {
@ -112,7 +112,7 @@ if(!function_exists("get_final_link")) {
foreach($data as $k=>$v) {
$params[$k] = $v;
}
if(count($params) > 0) {
$link = $base_url . "?" . http_build_query($params);
} else {
@ -207,7 +207,7 @@ if(!function_exists("get_requested_values")) {
$values[$name] = get_requested_value($name);
}
}
return $values;
}
}
@ -222,7 +222,7 @@ if(!function_exists("empty_requested_value")) {
if(!function_exists("get_binded_requests")) {
function get_binded_requests($rules, $method="_ALL") {
$data = array();
foreach($rules as $k=>$v) {
if(!empty($v)) {
$data[$v] = get_requested_value($k);