Update database.php

This commit is contained in:
Namhyeon Go 2020-01-09 21:26:03 +09:00 committed by GitHub
parent 2b9a3e7885
commit 384ecc9ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,22 +102,20 @@ if(!function_exists("get_db_binded_sql")) {
} }
if(!check_function_exists("get_db_stmt")) { if(!check_function_exists("get_db_stmt")) {
function get_db_stmt($sql, $bind=array(), $bind_pdo=false, $show_sql=false) { function get_db_stmt($sql, $bind=array(), $options=array()) {
$sql = !$bind_pdo ? get_db_binded_sql($sql, $bind) : $sql; $stmt = NULL;
$stmt = get_dbc_object()->prepare($sql);
$dbc = get_dbc_object();
$binder = get_value_in_array("binder", $options, "php");
if($show_sql) { if($binder == "pdo") {
set_error($sql, "DATABASE-SQL"); $stmt = $dbc->prepare($sql);
show_errors(false); foreach($bind as $k=>$v) {
} $stmt->bindParam(sprintf(":%s", $k), $v);
// bind parameter by PDO statement
if($bind_pdo) {
if(check_array_length($bind, 0) > 0) {
foreach($bind as $k=>$v) {
$stmt->bindParam(':' . $k, $v);
}
} }
} else {
$sql = get_db_binded_sql($sql, $bind);
$stmt = $dbc->prepare($sql);
} }
return $stmt; return $stmt;
@ -155,10 +153,14 @@ if(!check_function_exists("exec_db_query")) {
// check sql insert or not // check sql insert or not
if($terms[0] == "insert") { if($terms[0] == "insert") {
$stmt = get_db_stmt($sql); $stmt = get_db_stmt($sql, $bind, array(
$flag = $stmt->execute($bind) "binder" => "pdo"
));
$flag = $stmt->execute($bind);
} else { } else {
$stmt = get_db_stmt($sql, $bind); $stmt = get_db_stmt($sql, $bind, array(
"binder" => "php"
));
$flag = $stmt->execute(); $flag = $stmt->execute();
} }