fork download
  1.  
  2.  
  3. <?php
  4.  
  5. include(ROOT.'/components/Db.php');
  6. class News {
  7.  
  8. public static function getNewsItemById($id){
  9. $id = intval($id);
  10.  
  11. if($id){
  12.  
  13. $db = Db::getConnection();
  14.  
  15. $result = $db->query('SELECT * FROM news WHERE id='.$id);
  16.  
  17. $newItem = $result->fetch();
  18.  
  19. return $newItem;
  20. }
  21.  
  22.  
  23. }
  24.  
  25. public static function getNewsList(){
  26. $db = Db::getConnection();
  27.  
  28. $newsList = array();
  29. $result = $db->query('SELECT * FROM news');
  30.  
  31.  
  32. $i = 0;
  33. while($row = $result->fetch()){
  34.  
  35. $newsList[$i]['id'] = $row['id'];
  36. $newsList[$i]['title'] = $row['title'];
  37. $newsList[$i]['short_content'] = $row['short_content'];
  38. $newsList[$i]['content'] = $row['Content'];
  39. $i++;
  40. }
  41.  
  42. return $newsList;
  43. }
  44. }
  45.  
Success #stdin #stdout #stderr 0.02s 52480KB
stdin
Standard input is empty
stdout

stderr
PHP Notice:  Use of undefined constant ROOT - assumed 'ROOT' in /home/LTvm5C/prog.php on line 5
PHP Warning:  include(ROOT/components/Db.php): failed to open stream: No such file or directory in /home/LTvm5C/prog.php on line 5
PHP Warning:  include(): Failed opening 'ROOT/components/Db.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/LTvm5C/prog.php on line 5