Commit c7d78960 authored by MBoretto's avatar MBoretto

table_prefix as internal member

parent 33112c89
......@@ -38,6 +38,13 @@ class DB
*/
static protected $pdo;
/**
* table prefix
*
* @var string
*/
static protected $table_prefix;
/**
* Initialize
*
......@@ -49,6 +56,7 @@ class DB
throw new TelegramException('MySQL credentials not provided!');
}
self::$mysql_credentials = $credentials;
self::$table_prefix = $table_prefix;
$dsn = 'mysql:host=' . $credentials['host'] . ';dbname=' . $credentials['database'];
$options = array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',);
......@@ -56,10 +64,20 @@ class DB
$pdo = new \PDO($dsn, $credentials['user'], $credentials['password'], $options);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
//Define table
define('TB_MESSAGES', $table_prefix.'messages');
define('TB_USERS', $table_prefix.'users');
define('TB_CHATS', $table_prefix.'chats');
define('TB_USERS_CHATS', $table_prefix.'users_chats');
if (!defined('TB_MESSAGES')) {
define('TB_MESSAGES', self::$table_prefix.'messages');
}
if (!defined('TB_USERS')) {
define('TB_USERS', self::$table_prefix.'users');
}
if (!defined('TB_CHATS')) {
define('TB_CHATS', self::$table_prefix.'chats');
}
if (!defined('TB_USERS_CHATS')) {
define('TB_USERS_CHATS', self::$table_prefix.'users_chats');
}
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment