Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function createCategory($parent_id, $category_name) {
- $sql = "
- LOCK TABLE categories WRITE;
- SELECT @parentDepth :=category_depth FROM categories WHERE category_id = :parent;
- SELECT @myLeft := category_left FROM categories WHERE category_id = :parent;
- UPDATE categories SET category_right = category_right + 2 WHERE category_right > @myLeft;
- UPDATE categories SET category_left = category_left + 2 WHERE category_left > @myLeft;
- INSERT INTO categories(category_name, category_left, category_right, category_parent,category_depth)
- VALUES(:name, @myLeft + 1, @myLeft + 2, :parent,@parentDepth+1);
- UNLOCK TABLES;";
- $params = array(
- ':parent' => array(
- 'param' => $parent_id,
- 'type' => 1
- ),
- ':name' => array(
- 'param' => $category_name,
- 'type' => 2
- )
- );
- return $this->_query->query($sql, $params);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement