为什么我的查询不起作用?

时间:2011-09-13 03:51:10

标签: php database sqlite

我似乎无法让这个查询起作用。这是类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
        //MGHEN4023@GMAL.COM    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 个答案:

答案 0 :(得分: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