I am trying to add my external class to get, edit and add Database datas in Commands.
But that doesnt go, know i want to know:
The SDK allready have an mysql option integrated, i added details in hook.php.
And now i need to grab Database details for some Commands.
Like:
User sends Command /Points -> SDK connects to Database & Grabs his amount of Points -> Reply: You have 10 Points.
Kind Regards & with <3
Raphael
DB::getPdo() allows you to grab ready to use PDO object.
Could you make me please an example i dont understand right know ;(
Untested, should show you the right way.
<?php
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\DB;
class PointsCommand extends UserCommand
{
protected $name = 'points';
public function execute()
{
$message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$points = 0;
if ($result = DB::getPdo()->query('SELECT * FROM `points` WHERE `user_id` = ' . $user_id)) {
$result = $result->fetchAll();
$points = $result[0]['count'];
}
$data = [];
$data['chat_id'] = $chat_id;
$data['reply_to_message_id'] = $message_id;
$data['parse_mode'] = 'markdown';
$data['text'] = 'You have *' . $points . '* points.';
return Request::sendMessage($data);
}
}
Output: "You have 234 points."
This assumes the field containing the number of points is called count and user_id is unique field for table points.
Thanks, okey that is how i grab something, but how cann i update points to user in db or how can i insert a table with the SDK ?
Sry for that Questions but i tried it and it is frustrating.
It worked ;9 Thanks for every help
Just google up a for PDO tutorials, it's a PHP feature and there is a lot about it in the web.
You can see how records are added/updated in DB.php in the library.
Most helpful comment
Untested, should show you the right way.
Output: "You have 234 points."
This assumes the field containing the number of points is called
countanduser_idis unique field for tablepoints.