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