php-telegram-bot / core

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

USE THE DATABASE #1346

Closed MaiconKatty2 closed 2 years ago

MaiconKatty2 commented 2 years ago

hello, how can I work with the database in this library? wanted to make a system that saves certain information in the database.

could you give an example of using PDO within this library? an example that executes a query that saves information... an example of how to call pdo in this library and pass a query...

:/

fadilbjm commented 2 years ago

yes you can use database try like this in your command file

$conn = mysqli_connect('hostname', 'user', 'password, 'db_name);
$idUser = $this->getMessage()->getFrom()->getId();
$fetchUser = mysqli_query($conn, "SELECT id FROM users WHERE user_id = $idUser LIMIT 1");

or you can customize it

Hitmare commented 2 years ago

Hello

You can add Custom Tables to the included Database

You will need the following Classes in your Command File

use Longman\TelegramBot\DB;
use Longman\TelegramBot\Exception\TelegramException;
use PDO;
use PDOException;

Then within the Command build your PDO syntax. There are many PDO Tutorials in the Internet

$pdo = DB::getPdo();
$sql = 'INSERT INTO `table_name` (chat) VALUES (:chat)';
$sth = $pdo->prepare($sql);
$sth->bindValue(':chat', $chat_id);
MaiconKatty2 commented 2 years ago

Olá

Você pode adicionar tabelas personalizadas ao banco de dados incluído

Você precisará das seguintes classes em seu arquivo de comando

use Longman\TelegramBot\DB;
use Longman\TelegramBot\Exception\TelegramException;
use PDO;
use PDOException;

Em seguida, dentro do comando, construa sua sintaxe PDO. Existem muitos Tutoriais PDO na Internet

$pdo = DB::getPdo();
$sql = 'INSERT INTO `table_name` (chat) VALUES (:chat)';
$sth = $pdo->prepare($sql);
$sth->bindValue(':chat', $chat_id);

Okay, thank you!

MaiconKatty2 commented 2 years ago

yes you can use database try like this in your command file

$conn = mysqli_connect('hostname', 'user', 'password, 'db_name);
$idUser = $this->getMessage()->getFrom()->getId();
$fetchUser = mysqli_query($conn, "SELECT id FROM users WHERE user_id = $idUser LIMIT 1");

or you can customize it

Okay, thank you!