<?php
class News {
public function getNewsItemById($id){
}
public function getNewsList(){
$host = 'localhost';
$dbname = 'MVC';
$user = 'root';
$password = '';
$db = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
$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;
}
}
PD9waHAKCgpjbGFzcyBOZXdzIHsKCiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0TmV3c0l0ZW1CeUlkKCRpZCl7CgogICAgfQoKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXROZXdzTGlzdCgpewogICAgICAgICRob3N0ID0gJ2xvY2FsaG9zdCc7CiAgICAgICAgJGRibmFtZSA9ICdNVkMnOwogICAgICAgICR1c2VyID0gJ3Jvb3QnOwogICAgICAgICRwYXNzd29yZCA9ICcnOwogICAgICAgICRkYiA9IG5ldyBQRE8oIm15c3FsOmhvc3Q9JGhvc3Q7ZGJuYW1lPSRkYm5hbWUiLCAkdXNlciwgJHBhc3N3b3JkKTsKCiAgICAgICAgJG5ld3NMaXN0ID0gYXJyYXkoKTsKCiAgICAgICAgJHJlc3VsdCA9ICAkZGItPnF1ZXJ5KCdTRUxFQ1QgaWQsIHRpdGxlLCBkYXRlLCBzaG9ydF9jb250ZW50IEZST00gbmV3cyBPUkRFUiBCWSBkYXRlIERFU0MgTElNSVQgMTAnKTsKCgogICAgICAgICRpID0gMDsKICAgICAgICB3aGlsZSgkcm93ID0gJHJlc3VsdC0+ZmV0Y2goKSl7CiAgICAgICAgICAgICRuZXdzTGlzdFtpXVsnaWQnXSA9ICRyb3dbJ2lkJ107CiAgICAgICAgICAgICRuZXdzTGlzdFtpXVsndGl0bGUnXSA9ICRyb3dbJ3RpdGxlJ107CiAgICAgICAgICAgICRuZXdzTGlzdFtpXVsnZGF0ZSddID0gJHJvd1snZGF0ZSddOwogICAgICAgICAgICAkbmV3c0xpc3RbaV1bJ3Nob3J0X2NvbnRlbnQnXSA9ICRyb3dbJ3Nob3J0X2NvbnRlbnQnXTsKICAgICAgICAgICAgJGkrKzsKICAgICAgICB9CgogICAgICAgIHJldHVybiAkbmV3c0xpc3Q7CiAgICAJfQp9