Longman\TelegramBot\DB::externalInitialize PHP Method

externalInitialize() public static method

Let you use the class with an external already existing Pdo Mysql connection.
public static externalInitialize ( PD\PDO $external_pdo_connection, Telegram $telegram, string $table_prefix = null ) : PD\PDO
$external_pdo_connection PD\PDO PDO database object
$telegram Telegram Telegram object to connect with this object
$table_prefix string Table prefix
return PD\PDO PDO database object
    public static function externalInitialize($external_pdo_connection, Telegram $telegram, $table_prefix = null)
    {
        if ($external_pdo_connection === null) {
            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::defineTables();
        return self::$pdo;
    }

Usage Example

 /**
  * Initialize Database external connection
  *
  * @param /PDO    $external_pdo_connection PDO database object
  * @param string $table_prefix
  */
 public function enableExternalMysql($external_pdo_connection, $table_prefix = null)
 {
     $this->pdo = DB::externalInitialize($external_pdo_connection, $this, $table_prefix);
     ConversationDB::initializeConversation();
     $this->mysql_enabled = true;
 }