BotanDB
extends DB
in package
Class BotanDB
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
- initializeBotanDb() : mixed
- Initialize botan shortener table
- 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
- insertShortUrl() : bool
- Insert shortened URL into the 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
- selectShortUrl() : array<string|int, mixed>|bool
- Select cached shortened URL from the database
- 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
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
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
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
Return values
PDO —PDO database object
initializeBotanDb()
Initialize botan shortener table
public
static initializeBotanDb() : mixed
Return values
mixed —insertCallbackQueryRequest()
Insert callback query request into database
public
static insertCallbackQueryRequest(CallbackQuery $callback_query) : bool
Parameters
- $callback_query : CallbackQuery
Tags
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
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
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
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
Return values
bool —If the insert was successful
insertMessageRequest()
Insert Message request in db
public
static insertMessageRequest(Message $message) : bool
Parameters
- $message : Message
Tags
Return values
bool —If the insert was successful
insertRequest()
Insert request into database
public
static insertRequest(Update $update) : bool
Parameters
- $update : Update
Tags
Return values
bool —insertShortUrl()
Insert shortened URL into the database
public
static insertShortUrl(string $url, string $user_id, string $short_url) : bool
Parameters
- $url : string
- $user_id : string
- $short_url : string
Tags
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
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
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
Tags
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
Tags
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
Return values
array<string|int, mixed>|bool —Fetched data or false if not connected
selectShortUrl()
Select cached shortened URL from the database
public
static selectShortUrl(string $url, string $user_id) : array<string|int, mixed>|bool
Parameters
- $url : string
- $user_id : string
Tags
Return values
array<string|int, mixed>|bool —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
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
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)