Location: PHPKode > scripts > Nested Set DB Table > tests/1/demo.php
 * Demo script, which shows how can you use methods that are 
 * provided in NestedSetDbTable class. This is just observable 
 * script and you can't really try it, because there is no 
 * appropriate table in your database. 
 * @author Nikola Posa <hide@address.com>
 * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License
define('BASE_PATH', realpath(dirname(__FILE__)));

set_include_path('.' . PATH_SEPARATOR . BASE_PATH  
    . PATH_SEPARATOR . get_include_path());


//We must provide database adapter which implements NestedSetDbTable_DbAdapter_Interface, 
//and in this example, we're setting default adapter for all NestedSetDbTable instances. 
//This is usually done in some bootstrap file. We will use NestedSetDbTable_DbAdapter_Default, 
//which comes with NestedSetDbTable package.
//We can also pass db adapter instance to the constructor of our NestedSetDbTable model.
DbTable_NestedCategory::setDefaultAdapter(new NestedSetDbTable_DbAdapter_Default(array('dsn'=>'mysql:dbname=test;host=', 'username'=>'root', 'password'=>'')));

$nestedCategory = new DbTable_NestedCategory();

//Displaying whole tree.

//Inserting new node as a "next sibling" of a node which id is 2.
$data = array('name'=>'TEST');
$nestedCategory->insertNode($data, 2, NestedSetDbTable_Abstract::NEXT_SIBLING);

//Updating node which id is 8, changing its name to TEST1 and moving 
//its position in tree to be "last child" of node with id 6.
$data = array('name'=>'TEST1');
$nestedCategory->updateNode($data, 2, 6, NestedSetDbTable_Abstract::NEXT_SIBLING);

//Deleting node which id is 6, but without deleting its child nodes.

//Deleting node which id is 2 with all of its child nodes.
$nestedCategory->deleteNode(2, true);
Return current item: Nested Set DB Table