Documentation

DB
in package

Table of Contents

$mysql_credentials  : array<string|int, mixed>
MySQL credentials
$pdo  : PDO
PDO object
$table_prefix  : string
Table prefix
$telegram  : Telegram
Telegram class object
entitiesArrayToJson()  : mixed
Convert array of Entity items to a JSON array
externalInitialize()  : PDO
External Initialize
getPdo()  : PDO
Get the PDO object of the connected database
getTelegramRequestCount()  : array<string|int, mixed>|bool
Get Telegram API request count for current chat / message
initialize()  : PDO
Initialize
insertCallbackQueryRequest()  : bool
Insert callback query request into database
insertChat()  : bool
Insert chat
insertChosenInlineResultRequest()  : bool
Insert chosen inline result request into database
insertEditedMessageRequest()  : bool
Insert Edited Message request in db
insertInlineQueryRequest()  : bool
Insert inline query request into database
insertMessageRequest()  : bool
Insert Message request in db
insertRequest()  : bool
Insert request into database
insertTelegramRequest()  : bool
Insert Telegram API request in db
insertTelegramUpdate()  : bool
Insert entry to telegram_update table
insertUser()  : bool
Insert users and save their connection to chats
isDbConnected()  : bool
Check if database connection has been created
selectChats()  : array<string|int, mixed>|bool
Select Groups, Supergroups, Channels and/or single user Chats (also by ID or text)
selectMessages()  : array<string|int, mixed>|bool
Fetch message(s) from DB
selectTelegramUpdate()  : array<string|int, mixed>|bool
Fetch update(s) from DB
update()  : bool
Bulk update the entries of any table
defineTables()  : mixed
Define all the tables with the proper prefix
getTimestamp()  : string
Convert from unix timestamp to timestamp

Properties

$mysql_credentials

MySQL credentials

protected static array<string|int, mixed> $mysql_credentials = []

$pdo

PDO object

protected static PDO $pdo

$table_prefix

Table prefix

protected static string $table_prefix

$telegram

Telegram class object

protected static Telegram $telegram

Methods

entitiesArrayToJson()

Convert array of Entity items to a JSON array

public static entitiesArrayToJson(array<string|int, mixed>|null $entities[, mixed $default = null ]) : mixed
Parameters
$entities : array<string|int, mixed>|null
$default : mixed = null
Tags
todo

Find a better way, as json_* functions are very heavy

Return values
mixed

externalInitialize()

External Initialize

public static externalInitialize(PDO $external_pdo_connection, Telegram $telegram[, string $table_prefix = null ]) : PDO

Let you use the class with an external already existing Pdo Mysql connection.

Parameters
$external_pdo_connection : PDO

PDO database object

$telegram : Telegram

Telegram object to connect with this object

$table_prefix : string = null

Table prefix

Tags
throws
TelegramException
Return values
PDO

PDO database object

getPdo()

Get the PDO object of the connected database

public static getPdo() : PDO
Return values
PDO

getTelegramRequestCount()

Get Telegram API request count for current chat / message

public static getTelegramRequestCount([int $chat_id = null ][, string $inline_message_id = null ]) : array<string|int, mixed>|bool
Parameters
$chat_id : int = null
$inline_message_id : string = null
Tags
throws
TelegramException
Return values
array<string|int, mixed>|bool

Array containing TOTAL and CURRENT fields or false on invalid arguments

initialize()

Initialize

public static initialize(array<string|int, mixed> $credentials, Telegram $telegram[, string $table_prefix = null ][, string $encoding = 'utf8mb4' ]) : PDO
Parameters
$credentials : array<string|int, mixed>

Database connection details

$telegram : Telegram

Telegram object to connect with this object

$table_prefix : string = null

Table prefix

$encoding : string = 'utf8mb4'

Database character encoding

Tags
throws
TelegramException
Return values
PDO

PDO database object

insertCallbackQueryRequest()

Insert callback query request into database

public static insertCallbackQueryRequest(CallbackQuery $callback_query) : bool
Parameters
$callback_query : CallbackQuery
Tags
throws
TelegramException
Return values
bool

If the insert was successful

insertChat()

Insert chat

public static insertChat(Chat $chat[, string $date = null ][, string $migrate_to_chat_id = null ]) : bool
Parameters
$chat : Chat
$date : string = null
$migrate_to_chat_id : string = null
Tags
throws
TelegramException
Return values
bool

If the insert was successful

insertChosenInlineResultRequest()

Insert chosen inline result request into database

public static insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result) : bool
Parameters
$chosen_inline_result : ChosenInlineResult
Tags
throws
TelegramException
Return values
bool

If the insert was successful

insertEditedMessageRequest()

Insert Edited Message request in db

public static insertEditedMessageRequest(Message $edited_message) : bool
Parameters
$edited_message : Message
Tags
throws
TelegramException
Return values
bool

If the insert was successful

insertInlineQueryRequest()

Insert inline query request into database

public static insertInlineQueryRequest(InlineQuery $inline_query) : bool
Parameters
$inline_query : InlineQuery
Tags
throws
TelegramException
Return values
bool

If the insert was successful

insertMessageRequest()

Insert Message request in db

public static insertMessageRequest(Message $message) : bool
Parameters
$message : Message
Tags
todo

Complete with new fields: https://core.telegram.org/bots/api#message

throws
TelegramException
Return values
bool

If the insert was successful

insertRequest()

Insert request into database

public static insertRequest(Update $update) : bool
Parameters
$update : Update
Tags
todo

self::$pdo->lastInsertId() - unsafe usage if expected previous insert fails?

throws
TelegramException
Return values
bool

insertTelegramRequest()

Insert Telegram API request in db

public static insertTelegramRequest(string $method, array<string|int, mixed> $data) : bool
Parameters
$method : string
$data : array<string|int, mixed>
Tags
throws
TelegramException
Return values
bool

If the insert was successful

insertTelegramUpdate()

Insert entry to telegram_update table

public static insertTelegramUpdate(string $id[, string $chat_id = null ][, string $message_id = null ][, string $inline_query_id = null ][, string $chosen_inline_result_id = null ][, string $callback_query_id = null ][, string $edited_message_id = null ]) : bool
Parameters
$id : string
$chat_id : string = null
$message_id : string = null
$inline_query_id : string = null
$chosen_inline_result_id : string = null
$callback_query_id : string = null
$edited_message_id : string = null
Tags
todo

Add missing values! See https://core.telegram.org/bots/api#update

throws
TelegramException
Return values
bool

If the insert was successful

insertUser()

Insert users and save their connection to chats

public static insertUser(User $user[, string $date = null ][, Chat $chat = null ]) : bool
Parameters
$user : User
$date : string = null
$chat : Chat = null
Tags
throws
TelegramException
Return values
bool

If the insert was successful

isDbConnected()

Check if database connection has been created

public static isDbConnected() : bool
Return values
bool

selectChats()

Select Groups, Supergroups, Channels and/or single user Chats (also by ID or text)

public static selectChats( $select_chats_params) : array<string|int, mixed>|bool
Parameters
$select_chats_params :
Tags
throws
TelegramException
Return values
array<string|int, mixed>|bool

selectMessages()

Fetch message(s) from DB

public static selectMessages([int $limit = null ]) : array<string|int, mixed>|bool
Parameters
$limit : int = null

Limit the number of messages to fetch

Tags
throws
TelegramException
Return values
array<string|int, mixed>|bool

Fetched data or false if not connected

selectTelegramUpdate()

Fetch update(s) from DB

public static selectTelegramUpdate([int $limit = null ][, string $id = null ]) : array<string|int, mixed>|bool
Parameters
$limit : int = null

Limit the number of updates to fetch

$id : string = null

Check for unique update id

Tags
throws
TelegramException
Return values
array<string|int, mixed>|bool

Fetched data or false if not connected

update()

Bulk update the entries of any table

public static update(string $table, array<string|int, mixed> $fields_values, array<string|int, mixed> $where_fields_values) : bool
Parameters
$table : string
$fields_values : array<string|int, mixed>
$where_fields_values : array<string|int, mixed>
Tags
throws
TelegramException
Return values
bool

defineTables()

Define all the tables with the proper prefix

protected static defineTables() : mixed
Return values
mixed

getTimestamp()

Convert from unix timestamp to timestamp

protected static getTimestamp([int $time = null ]) : string
Parameters
$time : int = null

Unix timestamp (if empty, current timestamp is used)

Return values
string

Search results