Skip to content

Commit 6ae024b

Browse files
committed
Add setting to define custom MySQL port.
1 parent 6e12b42 commit 6ae024b

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
77
### Added
88
- `ChatAction` class to simplify chat action selection.
99
- Telegram Games platform!
10+
- Ability to set custom MySQL port.
1011
### Changed
1112
- [:exclamation:][unreleased-bc-rename-constants] Rename and ensure no redefinition of constants: `BASE_PATH` -> `TB_BASE_PATH`, `BASE_COMMANDS_PATH` -> `TB_BASE_COMMANDS_PATH`.
1213
### Deprecated

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ $bot_username = 'username_bot';
272272

273273
$mysql_credentials = [
274274
'host' => 'localhost',
275+
'port' => 3306, // optional
275276
'user' => 'dbuser',
276277
'password' => 'dbpass',
277278
'database' => 'dbname',
@@ -412,6 +413,7 @@ If you want to save messages/users/chats for further usage in commands, create a
412413
```php
413414
$mysql_credentials = [
414415
'host' => 'localhost',
416+
'port' => 3306, // optional
415417
'user' => 'dbuser',
416418
'password' => 'dbpass',
417419
'database' => 'dbname',

src/DB.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public static function initialize(
7575
throw new TelegramException('MySQL credentials not provided!');
7676
}
7777

78-
$dsn = 'mysql:host=' . $credentials['host'] . ';dbname=' . $credentials['database'];
78+
$dsn = 'mysql:host=' . $credentials['host'] . ';dbname=' . $credentials['database'];
79+
if (!empty($credentials['port'])) {
80+
$dsn .= ';port=' . $credentials['port'];
81+
}
82+
7983
$options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $encoding];
8084
try {
8185
$pdo = new PDO($dsn, $credentials['user'], $credentials['password'], $options);

0 commit comments

Comments
 (0)