2011-09-13 53 views
-1

我似乎無法得到此查詢的工作。這裏是一個類的內容news_and_events爲什麼我的查詢不能工作?

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; 
     } 

然後我實現這個在我的index.php這樣

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); 

全部循環結束。

我得到了以下輸出

/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

在與sqlite的命令行運行做了同樣的SQL工作? – Thilo

回答

0

您正在使用ORDER BY用逗號分隔的兩倍。

嘗試像(未測試)

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