Update database.php
This commit is contained in:
@@ -102,7 +102,18 @@ include "root.php";
|
|||||||
}
|
}
|
||||||
$this->path = realpath($this->path);
|
$this->path = realpath($this->path);
|
||||||
if (file_exists($this->path.'/'.$this->db_name)) {
|
if (file_exists($this->path.'/'.$this->db_name)) {
|
||||||
$this->db = new PDO('sqlite:'.$this->path.'/'.$this->db_name); //sqlite 3
|
//connect to the database
|
||||||
|
$this->db = new PDO('sqlite:'.$this->path.'/'.$this->db_name); //sqlite 3
|
||||||
|
//enable foreign key constraints
|
||||||
|
$this->db->query('PRAGMA foreign_keys = ON;');
|
||||||
|
//add additional functions to SQLite so that they are accessible inside SQL
|
||||||
|
//bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
|
||||||
|
$this->db->sqliteCreateFunction('md5', 'php_md5', 1);
|
||||||
|
$this->db->sqliteCreateFunction('unix_timestamp', 'php_unix_timestamp', 1);
|
||||||
|
$this->db->sqliteCreateFunction('now', 'php_now', 0);
|
||||||
|
$this->db->sqliteCreateFunction('sqlitedatatype', 'php_sqlite_data_type', 2);
|
||||||
|
$this->db->sqliteCreateFunction('strleft', 'php_left', 2);
|
||||||
|
$this->db->sqliteCreateFunction('strright', 'php_right', 2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
echo "not found";
|
echo "not found";
|
||||||
@@ -1340,64 +1351,66 @@ include "root.php";
|
|||||||
} //class database
|
} //class database
|
||||||
} //!class_exists
|
} //!class_exists
|
||||||
|
|
||||||
if (!function_exists('php_md5')) {
|
//addtitional functions for sqlite
|
||||||
function php_md5($string) {
|
if (!function_exists('php_md5')) {
|
||||||
return md5($string);
|
function php_md5($string) {
|
||||||
|
return md5($string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('php_unix_time_stamp')) {
|
if (!function_exists('php_unix_time_stamp')) {
|
||||||
function php_unix_time_stamp($string) {
|
function php_unix_time_stamp($string) {
|
||||||
return strtotime($string);
|
return strtotime($string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('php_now')) {
|
if (!function_exists('php_now')) {
|
||||||
function php_now() {
|
function php_now() {
|
||||||
return date("Y-m-d H:i:s");
|
return date("Y-m-d H:i:s");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('php_left')) {
|
if (!function_exists('php_left')) {
|
||||||
function php_left($string, $num) {
|
function php_left($string, $num) {
|
||||||
return substr($string, 0, $num);
|
return substr($string, 0, $num);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('php_right')) {
|
if (!function_exists('php_right')) {
|
||||||
function php_right($string, $num) {
|
function php_right($string, $num) {
|
||||||
return substr($string, (strlen($string)-$num), strlen($string));
|
return substr($string, (strlen($string)-$num), strlen($string));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//example usage
|
|
||||||
/*
|
/*
|
||||||
//find
|
//example usage
|
||||||
require_once "resources/classes/database.php";
|
//find
|
||||||
$database = new database;
|
require_once "resources/classes/database.php";
|
||||||
$database->domain_uuid = $_SESSION["domain_uuid"];
|
$database = new database;
|
||||||
$database->type = $db_type;
|
$database->domain_uuid = $_SESSION["domain_uuid"];
|
||||||
$database->table = "v_extensions";
|
$database->type = $db_type;
|
||||||
$where[0]['name'] = 'domain_uuid';
|
$database->table = "v_extensions";
|
||||||
$where[0]['value'] = $_SESSION["domain_uuid"];
|
$where[0]['name'] = 'domain_uuid';
|
||||||
$where[0]['operator'] = '=';
|
$where[0]['value'] = $_SESSION["domain_uuid"];
|
||||||
$database->where = $where;
|
$where[0]['operator'] = '=';
|
||||||
$order_by[0]['name'] = 'extension';
|
$database->where = $where;
|
||||||
$database->order_by = $order_by;
|
$order_by[0]['name'] = 'extension';
|
||||||
$database->order_type = 'desc';
|
$database->order_by = $order_by;
|
||||||
$database->limit = '2';
|
$database->order_type = 'desc';
|
||||||
$database->offset = '0';
|
$database->limit = '2';
|
||||||
$database->find();
|
$database->offset = '0';
|
||||||
print_r($database->result);
|
$database->find();
|
||||||
//insert
|
print_r($database->result);
|
||||||
require_once "resources/classes/database.php";
|
//insert
|
||||||
$database = new database;
|
require_once "resources/classes/database.php";
|
||||||
$database->domain_uuid = $_SESSION["domain_uuid"];
|
$database = new database;
|
||||||
$database->type = $db_type;
|
$database->domain_uuid = $_SESSION["domain_uuid"];
|
||||||
$database->table = "v_ivr_menus";
|
$database->type = $db_type;
|
||||||
$fields[0]['name'] = 'domain_uuid';
|
$database->table = "v_ivr_menus";
|
||||||
$fields[0]['value'] = $_SESSION["domain_uuid"];
|
$fields[0]['name'] = 'domain_uuid';
|
||||||
$database->add();
|
$fields[0]['value'] = $_SESSION["domain_uuid"];
|
||||||
print_r($database->result);
|
$database->add();
|
||||||
|
print_r($database->result);
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user