[ class tree: Tree ] [ index: Tree ] [ all elements ]

Class: Tree_Memory_MDB2simple

Source Location: /Tree-0.3.3/Memory/MDB2simple.php

Class Overview


the MDB2 interface to the tree class



  • 2001/06/27



Inherited Variables

Inherited Methods

Class: Tree_OptionsMDB2

this constructor sets the options, since i normally need this and in case the constructor doesnt need to do anymore i already have it done :-)

Class: Tree_Common

gets all the children and grand children etc.
gets all the children-ids and grand children-ids
get the ids of the children of the given element
return the maximum depth of the tree
get the level, which is how far below the root the element with the given id is
returns all the options
get the id of the parent for the given element
this gets all the preceeding nodes, the parent and it's parent and so on
get the ids of the parents and all it's parents and so on it simply returns the ids of the elements returned by getParents()
gets the path to the element given by its id
returns the path as a string
returns if the given element has any children
returns if $childId is a child of $id
set a number of options which are simply given in an array
this constructor sets the options, since i normally need this and in case the constructor doesnt need to do anymore i already have it done :-)
this method gets all the children recursively

Class Details

[line 30]
the MDB2 interface to the tree class

[ Top ]

Class Variables

$options = array('order' => '',
                         'whereAddOn' => '',
                         'table' => '',
                         'columnNameMaps' => array(
                                   /* 'id'       => 'tree_id', // use "tree_id" as "id"
                                      'parentId' => 'parent_id',
                                      'prevId'   => 'previous_id',
                                      'name'     => 'nodeName'

[line 52]

  • Var: saves the options passed to the constructor. Valid options:
    • order: which column to order by when reading the data from the DB, this sorts the data even inside every level
    • whereAddOn: add on for the where clause, this string is simply added behind the WHERE in the select, so you better make sure its correct SQL :-), i.e. 'uid=3'. This is needed i.e. when you are saving many trees for different user in one table where each entry has a uid (user id)
    • columnNameMaps: the column-name maps are used for the "as" in the select queries so you can use any column name in the table and "map" it to the name that shall be used in the internal array, that is built, see the examples (in comments)
    • columnNameMaps: array for id/parentId/prevId/name table column names
  • Access: public

Type:   array
Overrides:   Array

[ Top ]

$table =

[line 69]

  • Var: the table where to read the tree data from can also be set using the DSN in the constructor
  • Access: public

Type:   string

[ Top ]

Method Detail

Tree_Memory_MDB2simple (Constructor)   [line 88]

Tree_Memory_MDB2simple Tree_Memory_MDB2simple( string $dsn, [array $options = array()])

set up this object
  • Access: public


string   $dsn   —  this is a DSN of the for that PEAR::DB uses it only that additionally you can add parameters like ...?table=test_table to define the table it shall work on
array   $options   —  additional options you can set

[ Top ]

add   [line 185]

mixed add( array $newValues, [ $parentId = 0])

adds _one_ new element in the tree under the given parent

the values' keys given have to match the db-columns, because the value gets inserted in the db directly to add an entire node containing children and so on see 'addNode()'

to be compatible with the MDB2nested, u can also give the parent and previd as the second and third parameter

  • Return: either boolean false on failure or the id of the inserted row
  • See: addNode
  • Access: public


array   $newValues   —  this array contains the values that shall be inserted in the db-table the key for each element is the name of the column
   $parentId   — 

[ Top ]

move   [line 270]

boolean move( integer $idToMove, integer $newParentId, [integer $newPrevId = 0])

move an entry under a given parent or behind a given entry
  • Return: true for success
  • Author: Wolfram Kriesing <>
  • Version: 2001/10/10
  • Access: public


integer   $idToMove   —  the id of the element that shall be moved
integer   $newParentId   —  the id of the element which will be the new parent
integer   $newPrevId   —  if prevId is given the element with the id idToMove shall be moved _behind_ the element with id=prevId if it is 0 it will be put at the beginning if no prevId is in the DB it can be 0 too and won't bother since it is not written in the DB anyway

[ Top ]

remove   [line 224]

boolean remove( mixed $id)

removes the given node
  • Return: true on success
  • Access: public


mixed   $id   —  the id of the node to be removed, or an array of id's to be removed

[ Top ]

setup   [line 109]

boolean setup( )

retrieve all the navigation data from the db and call build to build the tree in the array data and structure
  • Return: true on success
  • Access: public

[ Top ]

update   [line 308]

boolean update( $id, array $newData)

update an element in the DB
  • Return: true for success
  • Author: Wolfram Kriesing <>
  • Version: 2002/01/17
  • Access: public


array   $newData   —  all the new data, the key 'id' is used to elements are the data to fill in the DB
   $id   — 

[ Top ]

Documentation generated on Thu, 10 Dec 2015 05:48:54 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.