Longman\TelegramBot\DB::selectTelegramUpdate PHP Method

selectTelegramUpdate() public static method

Fetch update(s) from DB
public static selectTelegramUpdate ( integer $limit = null ) : array | boolean
$limit integer Limit the number of updates to fetch
return array | boolean Fetched data or false if not connected
    public static function selectTelegramUpdate($limit = null)
    {
        if (!self::isDbConnected()) {
            return false;
        }
        try {
            $sql = '
                SELECT `id`
                FROM `' . TB_TELEGRAM_UPDATE . '`
                ORDER BY `id` DESC
            ';
            if ($limit !== null) {
                $sql .= 'LIMIT :limit';
            }
            $sth = self::$pdo->prepare($sql);
            $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
            $sth->execute();
            return $sth->fetchAll(PDO::FETCH_ASSOC);
        } catch (PDOException $e) {
            throw new TelegramException($e->getMessage());
        }
    }

Usage Example

 /**
  * Handle getUpdates method
  *
  * @param int|null $limit
  * @param int|null $timeout
  *
  * @return \Longman\TelegramBot\Entities\ServerResponse
  */
 public function handleGetUpdates($limit = null, $timeout = null)
 {
     if (!DB::isDbConnected()) {
         return new Entities\ServerResponse(['ok' => false, 'description' => 'getUpdates needs MySQL connection!'], $this->bot_name);
     }
     //DB Query
     $last_update = DB::selectTelegramUpdate(1);
     //As explained in the telegram bot api documentation
     $offset = isset($last_update[0]['id']) ? $last_update[0]['id'] + 1 : null;
     $response = Request::getUpdates(['offset' => $offset, 'limit' => $limit, 'timeout' => $timeout]);
     if ($response->isOk()) {
         //Process all updates
         foreach ((array) $response->getResult() as $result) {
             $this->processUpdate($result);
         }
     }
     return $response;
 }
All Usage Examples Of Longman\TelegramBot\DB::selectTelegramUpdate