Advertisement
fabi0

Untitled

May 22nd, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. public function createCategory($parent_id, $category_name) {
  2.         $sql = "
  3.            LOCK TABLE categories WRITE;
  4.            SELECT @parentDepth :=category_depth FROM categories WHERE category_id = :parent;
  5.            SELECT @myLeft := category_left FROM categories WHERE category_id = :parent;
  6.            UPDATE categories SET category_right = category_right + 2 WHERE category_right > @myLeft;
  7.            UPDATE categories SET category_left = category_left + 2 WHERE category_left > @myLeft;
  8.            INSERT INTO categories(category_name, category_left, category_right, category_parent,category_depth)
  9.            VALUES(:name, @myLeft + 1, @myLeft + 2, :parent,@parentDepth+1);
  10.            UNLOCK TABLES;";
  11.         $params = array(
  12.             ':parent' => array(
  13.                 'param' => $parent_id,
  14.                 'type' => 1
  15.             ),
  16.             ':name' => array(
  17.                 'param' => $category_name,
  18.                 'type' => 2
  19.             )
  20.         );
  21.         return $this->_query->query($sql, $params);
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement