Update database.php

This commit is contained in:
FusionPBX 2016-10-20 15:03:52 -06:00 committed by GitHub
parent 063eb71b5f
commit fa55b67bb0
1 changed files with 62 additions and 49 deletions

View File

@ -102,7 +102,18 @@ include "root.php";
}
$this->path = realpath($this->path);
if (file_exists($this->path.'/'.$this->db_name)) {
//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 {
echo "not found";
@ -1340,6 +1351,7 @@ include "root.php";
} //class database
} //!class_exists
//addtitional functions for sqlite
if (!function_exists('php_md5')) {
function php_md5($string) {
return md5($string);
@ -1370,8 +1382,9 @@ if (!function_exists('php_right')) {
}
}
//example usage
/*
//example usage
//find
require_once "resources/classes/database.php";
$database = new database;