Exemplo n.º 1
0
 /**
  * Initialize
  *
  * @param array credential, string table_prefix
  */
 public static function initialize(array $credentials, $table_prefix = null)
 {
     if (empty($credentials)) {
         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');
     try {
         $pdo = new \PDO($dsn, $credentials['user'], $credentials['password'], $options);
         $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         //Define table
         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());
     }
     self::$pdo = $pdo;
     return self::$pdo;
 }
Exemplo n.º 2
0
 /**
  * External Initialize
  *
  * Let you use the class with an external already existing Pdo Mysql connection.
  *
  * @param \PDO      $external_pdo_connection PDO database object
  * @param Telegram $telegram                Telegram object to connect with this object
  * @param string   $table_prefix            Table prefix
  *
  * @return \PDO PDO database object
  * @throws TelegramException
  */
 public static function externalInitialize($external_pdo_connection, Telegram $telegram, $table_prefix = null)
 {
     if (empty($external_pdo_connection)) {
         throw new TelegramException('MySQL external connection not provided!');
     }
     self::$pdo = $external_pdo_connection;
     self::$telegram = $telegram;
     self::$mysql_credentials = null;
     self::$table_prefix = $table_prefix;
     self::defineTable();
     return self::$pdo;
 }
Exemplo n.º 3
0
 /**
  * Initialize
  *
  * @param array credential, string table_prefix
  */
 public static function initialize(array $credentials, Telegram $telegram, $table_prefix = null)
 {
     self::$telegram = $telegram;
     if (empty($credentials)) {
         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');
     try {
         $pdo = new \PDO($dsn, $credentials['user'], $credentials['password'], $options);
         $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         //Define table
         if (!defined('TB_TELEGRAM_UPDATE')) {
             define('TB_TELEGRAM_UPDATE', self::$table_prefix . 'telegram_update');
         }
         if (!defined('TB_MESSAGE')) {
             define('TB_MESSAGE', self::$table_prefix . 'message');
         }
         if (!defined('TB_INLINE_QUERY')) {
             define('TB_INLINE_QUERY', self::$table_prefix . 'inline_query');
         }
         if (!defined('TB_CHOSEN_INLINE_QUERY')) {
             define('TB_CHOSEN_INLINE_QUERY', self::$table_prefix . 'chosen_inline_query');
         }
         if (!defined('TB_USER')) {
             define('TB_USER', self::$table_prefix . 'user');
         }
         if (!defined('TB_CHAT')) {
             define('TB_CHAT', self::$table_prefix . 'chat');
         }
         if (!defined('TB_USER_CHAT')) {
             define('TB_USER_CHAT', self::$table_prefix . 'user_chat');
         }
     } catch (\PDOException $e) {
         throw new TelegramException($e->getMessage());
     }
     self::$pdo = $pdo;
     return self::$pdo;
 }