2011-09-13 11 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; 
     } 

である私は、この

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にこれを実装するすべてでは終わりをループします。

私は次はあなたが二回カンマで区切って、ORDER BYを使用している

/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

を出力しました。

はsqliteのコマンドラインで実行したとき

SELECT * FROM (SELECT month, year, item, item_link, item_description, image FROM events ORDER BY year LIMIT 1) AS queryresult ORDER BY month 
関連する問題