2011-09-13 34 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