[PHP] PDO, query gaat niet helemaal lekker

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Ik ben sinds kort bezig met het maken van een applicatie die gebruikt maakt van de PHP PDO. Nu ben ik een method aan het schrijven die met een mooie query alle level 1 items (uit een hierachie) dient op te halen, echter gaat het mis want de query() is namelijk false. Op het moment dat ik een andere query gebruik bijvoorbeeld SELECT * from tabel dan is hij wel true. De query zelf is ook goed, ik heb m een aantal keren rechtstreeks op de db uitgevoerd en dat gaat prima. Ziet iemand misschien of ik iets verkeerd doe?

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    * method: getLevel1Items
    *
    * this method selects all level 1 items from the database and returns it in a array
    * this method has no parameters
    * @access public
    * @return array this method returns an array with the all the level 1 items from the system (the array is auto indexed)
    */
    public function getLevel1Items()    {
        try {
            //search for all level 1 items
            $sSelect = $this->m_oDB->query('SELECT node.PageTitle, (COUNT(parent.PageTitle) - (sub_tree.depth + 1)) AS depth'
                                                . 'FROM Pages AS node,'
                                                . 'Pages AS parent,'
                                                . 'Pages AS sub_parent,'
                                                . '('
                                                . 'SELECT node.PageTitle, (COUNT(parent.PageTitle) - 1) AS depth'
                                                . 'FROM Pages AS node,'
                                                . 'Pages AS parent'
                                                . 'WHERE node.Lft BETWEEN parent.Lft AND parent.Rgt'
                                                . 'GROUP BY node.PageTitle'
                                                . 'ORDER BY node.Lft'
                                                . ')AS sub_tree'
                                                . 'WHERE node.Lft BETWEEN parent.Lft AND parent.Rgt'
                                                . 'AND node.Lft BETWEEN sub_parent.Lft AND sub_parent.Rgt'
                                                . 'AND sub_parent.PageTitle = sub_tree.PageTitle'
                                                . 'GROUP BY node.PageTitle'
                                                . 'HAVING depth = 3'
                                                . 'ORDER BY node.Lft;');
            if($sSelect == FALSE)   {
                throw new Exception('Query is false');
            }

            foreach($sSelect->fetchAll(PDO::FETCH_ASSOC) as $aRow)  {
                //add a auto indexed key to the array with the PageTitle from the categorie as the key value
                $aLevel1Items[] = $aRow['PageTitle'];
            }

            //return array with al existing categories in the system
            return $aLevel1Items;
        }   catch(Exception $e) {
                print $e->getMessage();
        }
    }
}


Alvast bedankt voor de moeite!

Acties:
  • 0 Henk 'm!

  • djc
  • Registratie: December 2001
  • Laatst online: 08-09 23:18

djc

In de documentatie lees ik zowel "If you do not fetch all of the data in a result set before issuing your next call to PDO::query(), your call may fail." als "When query() fails, the boolean false is returned."...

Rustacean


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Sorry, opgelost!
Kwam doordat ik geen whitespace had tussen de PHP seperators. Stom foutje.