Commit c7d78960 authored by MBoretto's avatar MBoretto

table_prefix as internal member

parent 33112c89
...@@ -38,6 +38,13 @@ class DB ...@@ -38,6 +38,13 @@ class DB
*/ */
static protected $pdo; static protected $pdo;
/**
* table prefix
*
* @var string
*/
static protected $table_prefix;
/** /**
* Initialize * Initialize
* *
...@@ -49,6 +56,7 @@ class DB ...@@ -49,6 +56,7 @@ class DB
throw new TelegramException('MySQL credentials not provided!'); throw new TelegramException('MySQL credentials not provided!');
} }
self::$mysql_credentials = $credentials; self::$mysql_credentials = $credentials;
self::$table_prefix = $table_prefix;
$dsn = 'mysql:host=' . $credentials['host'] . ';dbname=' . $credentials['database']; $dsn = 'mysql:host=' . $credentials['host'] . ';dbname=' . $credentials['database'];
$options = array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',); $options = array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',);
...@@ -56,10 +64,20 @@ class DB ...@@ -56,10 +64,20 @@ class DB
$pdo = new \PDO($dsn, $credentials['user'], $credentials['password'], $options); $pdo = new \PDO($dsn, $credentials['user'], $credentials['password'], $options);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
//Define table //Define table
define('TB_MESSAGES', $table_prefix.'messages');
define('TB_USERS', $table_prefix.'users'); if (!defined('TB_MESSAGES')) {
define('TB_CHATS', $table_prefix.'chats'); define('TB_MESSAGES', self::$table_prefix.'messages');
define('TB_USERS_CHATS', $table_prefix.'users_chats'); }
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) { } catch (\PDOException $e) {
throw new TelegramException($e->getMessage()); 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