Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Longman\TelegramBot\Commands\UserCommands;
- use Longman\TelegramBot\Commands\UserCommand;
- use Longman\TelegramBot\Request;
- class SearchCommand extends UserCommand
- {
- /**
- * @var string
- */
- protected $name = 'search';
- /**
- * @var string
- */
- protected $description = 'Search the db ftw rofl lol xd';
- /**
- * @var string
- */
- protected $usage = '/search <test>';
- /**
- * @var string
- */
- protected $version = '1.1.0';
- /**
- * Command execute method
- *
- * @return \Longman\TelegramBot\Entities\ServerResponse
- * @throws \Longman\TelegramBot\Exception\TelegramException
- */
- public function execute()
- {
- $message = $this->getMessage();
- $chat_id = $message->getChat()->getId();
- $text = "Results:". PHP_EOL;
- $input = trim($message->getText(true));
- $pdo = new PDO('mysql:host=localhost;dbname=DBNAME', 'DBUSER', 'DBPASSWD', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
- $statement = $pdo->prepare("SELECT table FROM collum WHERE cell = ?");
- $statement->execute(array($input));
- $orw = $statement->fetch();
- while($orw) {
- $text = $text." ".$orw['cell']. PHP_EOL;
- }
- $data = [
- 'chat_id' => $chat_id,
- 'text' => $text,
- ];
- return Request::sendMessage($data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement