Update database.php

This commit is contained in:
Namhyeon Go 2018-03-15 17:36:30 +09:00 committed by GitHub
parent d035483d20
commit bc362adbef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,13 +41,25 @@ if(!function_exists("get_dbc_object")) {
} }
if(!function_exists("get_db_stmt")) { if(!function_exists("get_db_stmt")) {
function get_db_stmt($sql, $bind=array()) { function get_db_stmt($sql, $bind=array(), $bind_pdo=false) {
$stmt = get_dbc_object()->prepare($sql); if(!$bind_pdo) {
if(count($bind) > 0) { if(count($bind) > 0) {
foreach($bind as $k=>$v) { foreach($bind as $k=>$v) {
$stmt->bindParam(':' . $k, $v, PDO::PARAM_STR); $sql = str_replace(":" . $k, "'" . addslashes($v) . "'", $sql);
} }
} }
}
$stmt = get_dbc_object()->prepare($sql);
// bind parameter by PDO statement
if($bind_pdo) {
if(count($bind) > 0) {
foreach($bind as $k=>$v) {
$stmt->bindParam(':' . $k, $v);
}
}
}
return $stmt; return $stmt;
} }
} }
@ -71,14 +83,7 @@ if(!function_exists("exec_db_query")) {
if(count($bind) > 0) { if(count($bind) > 0) {
$is_insert_with_bind = true; $is_insert_with_bind = true;
} }
} else if($sql_terms[0] == "update") { } else {
if(count($bind) > 0) {
foreach($bind as $k=>$v) {
$sql = str_replace(":" . $k, "'" . addslashes($v) . "'", $sql);
}
}
$stmt = get_db_stmt($sql);
} else{
$stmt = get_db_stmt($sql, $bind); $stmt = get_db_stmt($sql, $bind);
} }