Update database.php
This commit is contained in:
parent
e266e4a6ec
commit
68ee90a4ba
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user