Update database.php
This commit is contained in:
parent
2b9a3e7885
commit
384ecc9ed4
|
@ -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);
|
|
||||||
|
|
||||||
if($show_sql) {
|
$dbc = get_dbc_object();
|
||||||
set_error($sql, "DATABASE-SQL");
|
$binder = get_value_in_array("binder", $options, "php");
|
||||||
show_errors(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// bind parameter by PDO statement
|
if($binder == "pdo") {
|
||||||
if($bind_pdo) {
|
$stmt = $dbc->prepare($sql);
|
||||||
if(check_array_length($bind, 0) > 0) {
|
|
||||||
foreach($bind as $k=>$v) {
|
foreach($bind as $k=>$v) {
|
||||||
$stmt->bindParam(':' . $k, $v);
|
$stmt->bindParam(sprintf(":%s", $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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user