PHPackages                             george-zakharov/tree-structure - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. george-zakharov/tree-structure

ActiveProject[Database &amp; ORM](/categories/database)

george-zakharov/tree-structure
==============================

This project helps to operate with tree structure based on Nested Sets method via MySQL

00PHP

Since Feb 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/george-zakharov/tree-structure)[ Packagist](https://packagist.org/packages/george-zakharov/tree-structure)[ RSS](/packages/george-zakharov-tree-structure/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Tree structure project
======================

[](#tree-structure-project)

Files
-----

[](#files)

### index.php

[](#indexphp)

- It is the entrance of the Application.
- It requires *NodeHandler.php* and new object *NodeHandler* creates there.
- At the top of the code block the possible realization of the inserting and deleting of nodes is presented under comments.
- Inside `` block of html there are `$nodes->showTree()` and `$nodes->showTree(3)`that provides representation of **Nodes Tree** in two modes:
    - `$nodes->showTree()` show the whole **Tree of Nodes**,
    - `$nodes->showTree(3)` show the part of **Tree of Nodes** limited by **node** with `$id = 3`.

### main.css

[](#maincss)

- This is the main stylesheet of the application.

### App/DbConnector.php

[](#appdbconnectorphp)

- Provides connection to **Database** via singleton pattern.
- Parameters for connection stores in properties of the class *DbConnector*:
    - `$host` for host name,
    - `$db_name` for name of the **Database**,
    - `$user` for login,
    - `$pass` for password.
- Main methods are:
    - `getInstance()` for class *DbConnector*,
    - `getConnection()` for *PDO Object*.

### App/Model.php

[](#appmodelphp)

- This file store class *Model* to perform the operations with DB.
- Main methods are:
    - `getNodes()` to show show whole tree of nodes or its part,
    - `setNode()` to add new node to the tree,
    - `deleteNode()` to delete node from tree.

### App/NodeHandler.php

[](#appnodehandlerphp)

- This method gives the representation of nodes to page **index.php**.
- Main methods are:
    - `showTree()` to `echo` the whole tree of nodes or its part if *parameter* is provided,
    - `addNewNode()` to add now node to **Database** via **Model.php** to the root or specified level,
    - `deleteNode()` to delete node from **Database** via **Model.php** from the specified level or to delete the whole tree.

### tree-structure-example.sql

[](#tree-structure-examplesql)

- This is the dump of the tables of my local `tree-structure` **Database**.
- It is partly filled for example.

Database structure
------------------

[](#database-structure)

- Data stores via **[Nested Sets](http://phpwiki.ru/tree/ns)** method.
- For example is provided a catalogue (of cars) in such hierarchy:
- vehicle
    - Type (Motorcycle, Automobile)
        - Brand (Audi, BMW, Ford)
            - Model (A1, A2, Focus, etc.)
                - Year (1999, 2003, etc.)
- All nodes are *nested* on correspond levels.
- New root level near `vehicle` can be added. For example, `animal` with its own hierarchy of nodes, but bonded with near *root node* by `right_key` and `left_key`.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/12bd08c29e80d4176eec06841a30438acebf77a65e768502f139b75b5f9c610c?d=identicon)[George Zakharov](/maintainers/George%20Zakharov)

---

Top Contributors

[![george-zakharov](https://avatars.githubusercontent.com/u/11558952?v=4)](https://github.com/george-zakharov "george-zakharov (11 commits)")

---

Tags

databasemysqlphpsql

### Embed Badge

![Health badge](/badges/george-zakharov-tree-structure/health.svg)

```
[![Health](https://phpackages.com/badges/george-zakharov-tree-structure/health.svg)](https://phpackages.com/packages/george-zakharov-tree-structure)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
