diff --git a/helper/database.alt.php b/helper/database.alt.php index 6144ab1..69a2d25 100644 --- a/helper/database.alt.php +++ b/helper/database.alt.php @@ -3,13 +3,14 @@ * @file database.alt.php * @date 2018-09-10 * @author Go Namhyeon - * @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; + } +}