azverin

AL+MP one-to-many Usage

Feb 27th, 2012
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2.  
  3.     require dir(__FILE__).'/tree.php';
  4.  
  5.     try {
  6.         $pdo = new PDO( 'mysql:dbname=db;host=localhost', 'admin', 'qwerty' );
  7.     } catch ( Exception $e ) {
  8.         echo 'Connection failed: ' . $e->getMessage();
  9.     }
  10.     Tree::SetConnection($pdo);
  11.  
  12.     //Создание структуры страниц
  13.     Tree::Fixture( 'pages', 1000, 5 );
  14.  
  15.     //Построение дерева из таблицы по ключу parent_id
  16.     $arr = Tree::GetTree( 'pages' );
  17.     //echo '<pre>'.print_r ( $arr, 1 ).'</pre>';
  18.  
  19.     //Построение путей в таблице
  20.     $time = microtime(true);
  21.     Tree::GeneratePaths('pages');
  22.     echo microtime(true)-$time.' с.';
  23.  
  24.     //Путь к элементу
  25.     $arr = Tree::GetPath('pages', 700);
  26.     echo '<pre>'.print_r ( $arr, 1 ).'</pre>';
  27.  
  28.     //Получение всех детей
  29.     $arr = Tree::GetChildren('pages', 40);
  30.     echo '<pre>'.print_r ( $arr, 1 ).'</pre>';
  31.  
  32.     //Количество детей
  33.     echo Tree::GetChildrenCount('pages', 2);
Advertisement
Add Comment
Please, Sign In to add comment