fork 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 = 'MCV';
  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'
  20. .'FROM news'
  21. .'ORDER BY date DESC'
  22. .'LIMIT 10');
  23.  
  24.  
  25. $i = 0;
  26. while($row = $result->fetch()){
  27. $newsList[i]['id'] = $row['id'];
  28. $newsList[i]['title'] = $row['title'];
  29. $newsList[i]['date'] = $row['date'];
  30. $newsList[i]['short_content'] = $row['short_content'];
  31. $i++;
  32. }
  33.  
  34. return $newsList;
  35. }
  36. }
  37.  
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Standard output is empty