php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.9k stars 955 forks source link

Custom data in MySQL #586

Closed blogaster closed 7 years ago

blogaster commented 7 years ago

Hi! Can I make custom table in DB and insert my data? I try

//Any config
//...

use Longman\TelegramBot\Exception\TelegramException;
use PDO;
use PDOException;
//...
if (!self::isDbConnected()) {
  return false;
}

$sth = self::$pdo->prepare('INSERT INTO `mutable` (`chat_id`, `city`) VALUES (:chat_id, :city) ON DUPLICATE KEY UPDATE city = :city');

$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':city', $city, PDO::PARAM_STR);
$sth->execute();

But isDbConnected() always returns false enableMySql is set

noplanman commented 7 years ago

Take a look at ConversationDB.php to see how you could extend the DB.

Of course you could also use DB::getPdo() to get a PDO object anywhere in your code after initialising the Telegram object, that you can then use to execute any SQL you'd like.

blogaster commented 7 years ago

Thank you I finded B::getPdo() in other issue and use success it!

Can you tell me how to connect the administrator commands?

noplanman commented 7 years ago

Have a look in the readme: https://github.com/php-telegram-bot/core#admin-commands

I'll close here as this is a different topic. Feel free to reach out on telegram: @noplanman