What are the potential pitfalls of using nested sets model in PHP for hierarchical data?

One potential pitfall of using the nested sets model in PHP for hierarchical data is the complexity of updating the tree structure, especially when adding, deleting, or moving nodes. To solve this issue, you can implement a recursive function to update the left and right values of nodes in the tree after any modification.

function updateNestedSets($parentId, $leftValue, $rightValue, $increment) {
    // Update the left and right values of nodes in the tree
    $query = "UPDATE table_name SET left_value = left_value + $increment WHERE left_value >= $leftValue AND parent_id = $parentId";
    $result = mysqli_query($connection, $query);
    
    $query = "UPDATE table_name SET right_value = right_value + $increment WHERE right_value >= $rightValue AND parent_id = $parentId";
    $result = mysqli_query($connection, $query);
}