Update database.php

This commit is contained in:
Namhyeon Go 2018-02-12 14:43:57 +09:00 committed by GitHub
parent e266e4a6ec
commit 68ee90a4ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,3 +25,58 @@ if(!function_exists("sql_query")) {
return $stmt;
}
}
function get_db_stmt($sql, $bind=array()) {
global $dbc;
$stmt = $dbc->prepare($sql);
if(count($bind) > 0) {
foreach($bind as $k=>$v) {
$stmt->bindParam(':' . $k, $v);
}
}
return $stmt;
}
function get_db_last_id() {
global $dbc;
return $dbc->lastInsertId();
}
function exec_db_query($sql, $bind=array(), $options=array()) {
global $dbc;
$flag = false;
$stmt = get_db_stmt($sql, $bind);
$validOptions = array();
$optionAvailables = array("is_check_count", "is_commit");
foreach($optionAvailables as $opt) {
if(!array_key_empty($opt, $options)) {
$validOptions[$opt] = $options[$opt];
} else {
$validOptions[$opt] = false;
}
}
extract($validOptions);
if($is_commit) {
$dbc->beginTransaction();
}
if($is_check_count == true) {
if($stmt->execute() && $stmt->rowCount() > 0) {
$flag = true;
}
} else {
$flag = $stmt->execute();
}
if($is_commit) {
$dbc->commit();
}
return $flag;
}