PhpBotFramework  2.0.2
A framework for Telegram Bots' APIs.
Modules | Functions
Database

Modules

 Users handling
 Handle bot users on the database.
 

Functions

 PhpBotFramework\Database\Database::__construct (BasicBot &$bot)
 
bool PhpBotFramework\Database\Database::connect (array $params)
 Open a database connection using PDO. More...
 
static array PhpBotFramework\Database\Database::addDefaultValue (array $params)
 
static string PhpBotFramework\Database\Database::getDns ($params)
 
 PhpBotFramework\Database\Database::sanitizeUserTable ()
 
int PhpBotFramework\Database\LongPolling::getUpdateOffsetRedis (string $offset_key)
 
 PhpBotFramework\Database\LongPolling::getUpdatesRedis (int $limit=100, int $timeout=60, string $offset_key='offset')
 Get updates received by the bot, and use Redis to save and get the last offset. More...
 
int PhpBotFramework\Database\LongPolling::getUpdateOffsetDatabase (string $table_name, string $column_name)
 
 PhpBotFramework\Database\LongPolling::getUpdatesDatabase (int $limit=100, int $timeout=0, string $table_name='telegram', string $column_name='bot_offset')
 Get updates received by the bot, using the SQL database to store and get the last offset. More...
 

Detailed Description

Function Documentation

◆ connect()

bool PhpBotFramework\Database\Database::connect ( array  $params)

Open a database connection using PDO.

Provides a simple way to initialize a database connection and create a PDO instance.

Parameters
array$paramsParameters for initialize connection. Index required:
  • username
  • password (can be an empty string) Optional index:
  • dbname
  • adapter Default: mysql
  • host Default: localhost
  • options (Array of options passed when creating PDO object)
Returns
bool True when the connection is succefully created.

◆ getDns()

static string PhpBotFramework\Database\Database::getDns (   $params)
static

Check if the current field matches one of the fields that are passed to PDO in another way and so don't need to be included in the string.

◆ getUpdatesDatabase()

PhpBotFramework\Database\LongPolling::getUpdatesDatabase ( int  $limit = 100,
int  $timeout = 0,
string  $table_name = 'telegram',
string  $column_name = 'bot_offset' 
)

Get updates received by the bot, using the SQL database to store and get the last offset.

It check if an offset exists on redis, then get it, or call getUpdates to set it. Then it start a loop where it process updates and update the offset on Redis. Each update is surrounded by a try/catch.

See also
getUpdates
Parameters
int$limitOptional. Limits the number of updates to be retrieved. Values between 1—100 are accepted.
int$timeoutOptional. Timeout (in seconds) for long polling.
string$table_nameOptional. Name of the table where offset is saved in the database.
string$column_nameOptional. Name of the column where the offset is saved in the database.

◆ getUpdatesRedis()

PhpBotFramework\Database\LongPolling::getUpdatesRedis ( int  $limit = 100,
int  $timeout = 60,
string  $offset_key = 'offset' 
)

Get updates received by the bot, and use Redis to save and get the last offset.

It check if an offset exists on Redis: then get it or call getUpdates to set it. Then it start a loop where it process updates and update the offset on Redis. Each update is surrounded by a try/catch.

See also
getUpdates
Parameters
int$limitOptional. Limits the number of updates to be retrieved. Values between 1—100 are accepted.
int$timeoutOptional. Timeout (in seconds) for long polling.
string$offset_keyOptional. Name of the variable where the offset is saved on Redis.