Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class News
- {
- /**
- * Returns single news item with specified id
- * @param $id
- *
- */
- public static function getNewsById($id)
- {
- $id = intval($id);
- if ($id) {
- // $host = 'localhost';
- // $dbname = 'mvc_site';
- // $user = 'root';
- // $password = '';
- // $db = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
- $db = DB::getConnection();
- $result = $db->query('SELECT * FROM news WHERE ID=' . $id);
- $result->setFetchMode(PDO::FETCH_ASSOC);
- $newsItem = $result->fetch();
- return $newsItem;
- }
- }
- /**
- * Returns an array of news items
- */
- public static function getNewsList()
- {
- //Запрос в БД
- $db = DB::getConnection();
- $newsList = array();
- $result = $db->query('SELECT id, title, date, short_content '
- . 'FROM news '
- . 'ORDER BY date DESC '
- . 'LIMIT 10');
- $i = 0;
- while ($row = $result->fetch()) {
- $newsList[$i]['id'] = $row['id'];
- $newsList[$i]['title'] = $row['title'];
- $newsList[$i]['date'] = $row['date'];
- $newsList[$i]['short_content'] = $row['short_content'];
- $i++;
- }
- return $newsList;
- }
- }
Add Comment
Please, Sign In to add comment