@@ 180-205 (lines=26) @@ | ||
177 | * @return array|bool Fetched data or false if not connected |
|
178 | * @throws \Longman\TelegramBot\Exception\TelegramException |
|
179 | */ |
|
180 | public static function selectTelegramUpdate($limit = null) |
|
181 | { |
|
182 | if (!self::isDbConnected()) { |
|
183 | return false; |
|
184 | } |
|
185 | ||
186 | try { |
|
187 | $sql = ' |
|
188 | SELECT `id` |
|
189 | FROM `' . TB_TELEGRAM_UPDATE . '` |
|
190 | ORDER BY `id` DESC |
|
191 | '; |
|
192 | ||
193 | if ($limit !== null) { |
|
194 | $sql .= 'LIMIT :limit'; |
|
195 | } |
|
196 | ||
197 | $sth = self::$pdo->prepare($sql); |
|
198 | $sth->bindParam(':limit', $limit, PDO::PARAM_INT); |
|
199 | $sth->execute(); |
|
200 | ||
201 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
|
202 | } catch (PDOException $e) { |
|
203 | throw new TelegramException($e->getMessage()); |
|
204 | } |
|
205 | } |
|
206 | ||
207 | /** |
|
208 | * Fetch message(s) from DB |
|
@@ 215-241 (lines=27) @@ | ||
212 | * @return array|bool Fetched data or false if not connected |
|
213 | * @throws \Longman\TelegramBot\Exception\TelegramException |
|
214 | */ |
|
215 | public static function selectMessages($limit = null) |
|
216 | { |
|
217 | if (!self::isDbConnected()) { |
|
218 | return false; |
|
219 | } |
|
220 | ||
221 | try { |
|
222 | $sql = ' |
|
223 | SELECT * |
|
224 | FROM `' . TB_MESSAGE . '` |
|
225 | WHERE `update_id` != 0 |
|
226 | ORDER BY `message_id` DESC |
|
227 | '; |
|
228 | ||
229 | if ($limit !== null) { |
|
230 | $sql .= 'LIMIT :limit'; |
|
231 | } |
|
232 | ||
233 | $sth = self::$pdo->prepare($sql); |
|
234 | $sth->bindParam(':limit', $limit, PDO::PARAM_INT); |
|
235 | $sth->execute(); |
|
236 | ||
237 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
|
238 | } catch (PDOException $e) { |
|
239 | throw new TelegramException($e->getMessage()); |
|
240 | } |
|
241 | } |
|
242 | ||
243 | /** |
|
244 | * Convert from unix timestamp to timestamp |