Advertisement
Hitmare

Untitled

Jul 19th, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. namespace Longman\TelegramBot\Commands\UserCommands;
  2.  
  3. use Longman\TelegramBot\Commands\UserCommand;
  4. use Longman\TelegramBot\Request;
  5.  
  6. class SearchCommand extends UserCommand
  7. {
  8.     /**
  9.      * @var string
  10.      */
  11.     protected $name = 'search';
  12.  
  13.     /**
  14.      * @var string
  15.      */
  16.     protected $description = 'Search the db ftw rofl lol xd';
  17.  
  18.     /**
  19.      * @var string
  20.      */
  21.     protected $usage = '/search <test>';
  22.  
  23.     /**
  24.      * @var string
  25.      */
  26.     protected $version = '1.1.0';
  27.  
  28.     /**
  29.      * Command execute method
  30.      *
  31.      * @return \Longman\TelegramBot\Entities\ServerResponse
  32.      * @throws \Longman\TelegramBot\Exception\TelegramException
  33.      */
  34.     public function execute()
  35.     {
  36.         $message = $this->getMessage();
  37.         $chat_id = $message->getChat()->getId();
  38.         $text = "Results:". PHP_EOL;
  39.         $input = trim($message->getText(true));
  40.         $pdo = new PDO('mysql:host=localhost;dbname=DBNAME', 'DBUSER', 'DBPASSWD', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
  41.         $statement = $pdo->prepare("SELECT table FROM collum WHERE cell = ?");
  42.         $statement->execute(array($input));
  43.         $orw = $statement->fetch();
  44.    
  45.     while($orw) {
  46.         $text = $text." ".$orw['cell']. PHP_EOL;
  47.     }
  48.  
  49.         $data = [
  50.             'chat_id' => $chat_id,
  51.             'text'    => $text,
  52.         ];
  53.  
  54.         return Request::sendMessage($data);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement