2011-09-13 8 views
-1

이 쿼리를 작동시키지 못했습니다. 다음은 클래스의 내용이 내가 모든 최종 루프이내 쿼리가 작동하지 않는 이유는 무엇입니까?

require_once('db_class.php'); 
      $db = new news_and_events(); 

      $months = array('','January','February','March','April','May','June','July','August','September','October','November','December','Spring','Summer','Fall','Winter'); 

      $database = array ('','humanitarian'); 

      $directory = array ('', './'); 

      if ($events !== FALSE) 


      { 
      for ($i = 1; $i <=1 ; $i++)   
      {      
       $db->connect($database[$i]); 
       $events = $db->events(1); 

처럼 내의 index.php에이에 구현

private $dbHandle; 

     public function connect() 
     { 
      try 
      { 
       echo dirname($_SERVER['SCRIPT_FILENAME']) . '/content.sqlite'; 
       $this->dbHandle = new PDO('sqlite:' . dirname($_SERVER['SCRIPT_FILENAME']) . '/content.sqlite'); 
      } 
      catch (PDOException $exception) 
      { 
       die($exception->getMessage()); 
      } 
     } 

     //MIKE GHEN'S FUNCTION 
     //[email protected] 2154781286 
     //THIS FUNCITON IS USED TO GET THE DATA FOR THE homepage_slider 

     public function disconnect() 
     { 
      /*if ($this->dbconn > 0) 
      { 
       sqlite_close($this->dbconn); 
      }*/ 
     } 

     public function events($pMaxRecords=0) 
     { 
      $records = array(); 

      $sql = 'SELECT month, year, item, item_link, item_description, image ' . 
        'FROM events ORDER BY year DESC, month DESC'; 
      if ($pMaxRecords > 0) 
      { 
       $sql .= ' LIMIT ' . $pMaxRecords; 
      } 
      $result = $this->dbHandle->query($sql); 
      //MG: DEBUG STATEMENT, You are seeing this because the query didnt work 
      if(!$results) {die("Error with query: ". $sql);} 
      $records = $result->fetchAll(PDO::FETCH_ASSOC); 
      return $records; 
      //$results = sqlite_array_query($this->dbconn, $sql, SQLITE_ASSOC);  
      //return $results; 
     } 

을 news_and_events입니다.

나는 두 번 쉼표로 구분하여 다음

/home/www/sedtapp/humanitarian/content.sqliteError with query: SELECT month, year, item, item_link, item_description, image FROM events ORDER BY year DESC, month DESC LIMIT 1 
+1

이 같은 SQL 작업을하는 것처럼 그것을 시도? – Thilo

답변

0

출력을 사용하는 ORDER를 얻었다.

은 (테스트되지 않음) sqlite가 명령 줄을 실행할 때

SELECT * FROM (SELECT month, year, item, item_link, item_description, image FROM events ORDER BY year LIMIT 1) AS queryresult ORDER BY month 
관련 문제