【发布时间】:2014-03-30 19:13:14
【问题描述】:
我正在尝试在 codeigniter 中创建一个基于 http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ 的嵌套类别系统
如果我直接在 mysql 中使用,下面的 sql 可以正常工作。但是,如果我在 CI 中将其用作查询字符串,则会出现 mysql 错误。有什么线索吗?
LOCK TABLE admin_category WRITE; SELECT @myRight:=`rgt` FROM `admin_category` WHERE `id` = 3; UPDATE `admin_category` SET `rgt` = rgt + 2 WHERE `rgt` > @myRight; UPDATE `admin_category` SET `lft` = lft + 2 WHERE `lft` > @myRight; INSERT INTO admin_category(name, lft, rgt) VALUES('AnotherCategory', @myRight + 1, @myRight + 2); UNLOCK TABLES;
我的模型中的部分功能:
$qString = "
LOCK TABLE $this->table WRITE;
SELECT @myRight:=`rgt` FROM `$this->table`
WHERE `id` = $prev_cat_id;
UPDATE `$this->table` SET `rgt` = rgt + 2 WHERE `rgt` > @myRight;
UPDATE `$this->table` SET `lft` = lft + 2 WHERE `lft` > @myRight;
INSERT INTO $this->table(name, lft, rgt) VALUES('$name', @myRight + 1, @myRight + 2);
UNLOCK TABLES;
";
$this->db->query($qString);
$inserted_id = $this->db->insert_id();
感谢阅读...
【问题讨论】:
标签: php mysql codeigniter nested