Update database.php

This commit is contained in:
Namhyeon Go 2019-07-14 13:34:58 +09:00 committed by GitHub
parent 5c3a5c8608
commit 4ee2a1128d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -214,11 +214,11 @@ if(!check_function_exists("exec_db_query")) {
return $flag; return $flag;
} }
} }
if(!check_function_exists("exec_db_fetch_all")) { if(!check_function_exists("exec_db_fetch_all")) {
function exec_db_fetch_all($sql, $bind=array(), $options=array()) { function exec_db_fetch_all($sql, $bind=array(), $options=array()) {
$response = array(); $response = array();
$length = 0;
$size = 0;
$is_not_countable = false; $is_not_countable = false;
$rows = array(); $rows = array();
@ -229,11 +229,13 @@ if(!check_function_exists("exec_db_fetch_all")) {
} }
if(array_key_equals("do_count", $options, true)) { if(array_key_equals("do_count", $options, true)) {
$count_sql = sprintf("select count(*) as cnt from (%s) a", get_db_binded_sql($sql, $bind)); $_sql = sprintf("select count(*) as cnt from (%s) a", get_db_binded_sql($sql, $bind));
$count_data = exec_db_fetch($count_sql); $_data = exec_db_fetch($_sql);
$length = get_value_in_array("cnt", $count_data, $length); $size = get_value_in_array("cnt", $_data, $size);
} elseif(array_key_equals("do_count", $options, "fn_count")) { } elseif(array_key_equals("do_count", $options, "count")) {
$length = count($rows); $size = count($rows);
} elseif(array_key_equals("do_count", $options, "PDOStatement::rowCount")) {
$size = $stmt->rowCount();
} else { } else {
$response = $rows; $response = $rows;
$is_not_countable = true; $is_not_countable = true;
@ -241,7 +243,10 @@ if(!check_function_exists("exec_db_fetch_all")) {
if(!$is_not_countable) { if(!$is_not_countable) {
$response = array( $response = array(
"length" => $length, "length" => $size, // compatible with RSF 1.4 or lower
"size" => $size, // use RSF 1.5 or above (recommended: size)
"cnt" => $size,
"count" => $size,
"data" => $rows, "data" => $rows,
); );
} }