Update database.alt.php

This commit is contained in:
Namhyeon Go 2018-09-11 11:36:46 +09:00 committed by GitHub
parent 3e6099a9e5
commit 0f864b57a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,13 +3,14 @@
* @file database.alt.php
* @date 2018-09-10
* @author Go Namhyeon <gnh1201@gmail.com>
* @brief Database alternative connecter
* @brief Database alternative driver switcher
*/
if(function_exists("get_db_alt_connect")) {
if(!function_exists("get_db_alt_connect")) {
function get_db_alt_connect($driver) {
$conn = false;
$config = get_config();
$rules = array(
array(
"driver" => "mysql.pdo",
@ -68,7 +69,7 @@ if(!function_exists("exec_db_alt_sql_query")) {
foreach($rules as $rule) {
if($rule['driver'] == $driver) {
if(loadHelper(sprintf("database.%s", $rule['driver']))) {
$result = function_exists($rule['callback']) ? call_user_func($rule['callback']) : $conn;
$result = function_exists($rule['callback']) ? call_user_func($rule['callback']) : $result;
}
break;
}
@ -77,3 +78,53 @@ if(!function_exists("exec_db_alt_sql_query")) {
return $result;
}
}
if(!function_exists("exec_db_alt_fetch_all")) {
function exec_db_alt_fetch_all($sql, $bind=array()) {
$rows = array();
$rules = array(
array(
"driver" => "mysql.pdo",
"callback" => "exec_db_mysql_pdo_fetch_all"
),
array(
"driver" => "mysql.imp",
"callback" => "exec_db_mysql_imp_fetch_all"
),
array(
"driver" => "mysql.old",
"callback" => "exec_db_mysql_old_fetch_all"
),
array(
"driver" => "oracle",
"callback" => "exec_db_oracle_fetch_all"
)
);
foreach($rules as $rule) {
if($rule['driver'] == $driver) {
if(loadHelper(sprintf("database.%s", $rule['driver']))) {
$rows = function_exists($rule['callback']) ? call_user_func($rule['callback']) : $rows;
}
break;
}
}
return $rows;
}
}
if(!function_exists("exec_db_alt_fetch")) {
function exec_db_alt_fetch($sql, $bind) {
$fetched = false;
$rows = exec_db_alt_fetch_all($sql, $bind);
foreach($rows as $row) {
$fetched = $row;
break;
}
return $fetched;
}
}