Update database.php

This commit is contained in:
Namhyeon Go 2019-04-01 16:44:45 +09:00 committed by GitHub
parent 25895fb771
commit 49520296be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -219,7 +219,10 @@ if(!check_function_exists("exec_db_query")) {
}
if(!check_function_exists("exec_db_fetch_all")) {
function exec_db_fetch_all($sql, $bind=array()) {
function exec_db_fetch_all($sql, $bind=array(), $options=array()) {
$response = array();
$length = 0;
$rows = array();
$stmt = get_db_stmt($sql, $bind);
@ -227,7 +230,20 @@ if(!check_function_exists("exec_db_fetch_all")) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
return $rows;
// Count rows
$count_data = exec_db_fetch(sprintf("select count(*) as cnt from (%s)", $sql));
$length = get_value_in_array("cnt", $count_data, $length);
if(array_key_equals("do_count", $options, true)) {
$response = array(
"length" => $length,
"data" => $rows,
);
} else {
$response = $rows;
}
return $response;
}
}