Update database.php
This commit is contained in:
parent
ac6cba6e50
commit
efb8c0dda7
|
@ -1,4 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
if(!function_exists("get_db_connect")) {
|
||||||
|
function get_db_connect() {
|
||||||
|
global $config;
|
||||||
|
|
||||||
$conn = new PDO(
|
$conn = new PDO(
|
||||||
sprintf(
|
sprintf(
|
||||||
"mysql:host=%s;dbname=%s;charset=utf8",
|
"mysql:host=%s;dbname=%s;charset=utf8",
|
||||||
|
@ -11,17 +15,32 @@ $conn = new PDO(
|
||||||
);
|
);
|
||||||
$conn->query("SET NAMES 'utf8'");
|
$conn->query("SET NAMES 'utf8'");
|
||||||
|
|
||||||
if(!function_exists("sql_query")) {
|
return $conn;
|
||||||
function sql_query($sql, $bind=array()) {
|
|
||||||
return get_db_stmt($sql, $bind);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_dbc_object() {
|
if(!function_exists("exec_stmt_query")) {
|
||||||
|
function exec_stmt_query($sql, $bind=array()) {
|
||||||
|
$stmt = get_db_stmt($sql, $bind);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
return $stmt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!function_exists("get_dbc_object")) {
|
||||||
|
function get_dbc_object($renew=false) {
|
||||||
global $dbc;
|
global $dbc;
|
||||||
|
|
||||||
|
if($renew) {
|
||||||
|
$dbc = get_db_connect();
|
||||||
|
}
|
||||||
|
|
||||||
return $dbc;
|
return $dbc;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!function_exists("get_db_stmt")) {
|
||||||
function get_db_stmt($sql, $bind=array()) {
|
function get_db_stmt($sql, $bind=array()) {
|
||||||
$stmt = get_dbc_object()->prepare($sql);
|
$stmt = get_dbc_object()->prepare($sql);
|
||||||
if(count($bind) > 0) {
|
if(count($bind) > 0) {
|
||||||
|
@ -31,11 +50,15 @@ function get_db_stmt($sql, $bind=array()) {
|
||||||
}
|
}
|
||||||
return $stmt;
|
return $stmt;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!function_exists("get_db_last_id")) {
|
||||||
function get_db_last_id() {
|
function get_db_last_id() {
|
||||||
return get_dbc_object()->lastInsertId();
|
return get_dbc_object()->lastInsertId();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!function_exists("exec_db_query")) {
|
||||||
function exec_db_query($sql, $bind=array(), $options=array()) {
|
function exec_db_query($sql, $bind=array(), $options=array()) {
|
||||||
$dbc = get_dbc_object();
|
$dbc = get_dbc_object();
|
||||||
|
|
||||||
|
@ -71,7 +94,9 @@ function exec_db_query($sql, $bind=array(), $options=array()) {
|
||||||
|
|
||||||
return $flag;
|
return $flag;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!function_exists("exec_db_fetch_all")) {
|
||||||
function exec_db_fetch_all($sql, $bind=array()) {
|
function exec_db_fetch_all($sql, $bind=array()) {
|
||||||
$rows = array();
|
$rows = array();
|
||||||
$stmt = get_db_stmt($sql, $bind);
|
$stmt = get_db_stmt($sql, $bind);
|
||||||
|
@ -82,6 +107,7 @@ function exec_db_fetch_all($sql, $bind=array()) {
|
||||||
|
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set global db connection variable
|
// set global db connection variable
|
||||||
$dbc = get_db_connect();
|
$dbc = get_db_connect();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user