fork(1) download
  1. <?php
  2.  
  3.  
  4. class News {
  5.  
  6. public function getNewsItemById($id){
  7.  
  8. }
  9.  
  10. public function getNewsList(){
  11. $host = 'localhost';
  12. $dbname = 'MVC';
  13. $user = 'root';
  14. $password = '';
  15. $db = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
  16.  
  17. $newsList = array();
  18.  
  19. $result = $db->query('SELECT id, title, date, short_content FROM news ORDER BY date DESC LIMIT 10');
  20.  
  21.  
  22. $i = 0;
  23. while($row = $result->fetch()){
  24. $newsList[i]['id'] = $row['id'];
  25. $newsList[i]['title'] = $row['title'];
  26. $newsList[i]['date'] = $row['date'];
  27. $newsList[i]['short_content'] = $row['short_content'];
  28. $i++;
  29. }
  30.  
  31. return $newsList;
  32. }
  33. }
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Standard output is empty