0

我已经按照 sql 查询来删除节点。

$sql="LOCK TABLE xp_subunit WRITE; ";
            $sql .= "SELECT @myLeft := ".$_GET['lft'].", @myRight :=  ".$_GET['rgt'].", @myWidth :=  ".$_GET['lft']." - lft + 1
            FROM xp_subunit
            WHERE id =".$_GET['id']."; ";

            $sql .= "DELETE FROM xp_subunit WHERE lft BETWEEN @myLeft AND @myRight; ";

            $sql .= "UPDATE xp_subunit SET rgt = rgt - @myWidth WHERE rgt > @myRight; ";
            $sql .= "UPDATE xp_subunit SET lft = lft - @myWidth WHERE lft > @myRight; ";
            $sql.="UNLOCK TABLES;";

            //echo $sql;
            echo $query = $this->db->query($sql);

我在 phpmyadmin 中尝试了这个查询,它成功执行并根据需要删除了节点。但是当我将它转换为 codeigniter 代码时,它会给出 mysql 语法错误,例如:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE FROM xp_subunit WHERE lft BETWEEN @myLeft AND @myRight;UPDATE xp_subunit ' at line 3

SELECT @myLeft := 1, @myRight := 29, @myWidth := 1 - lft + 1 FROM xp_subunit WHERE id =1; DELETE FROM xp_subunit WHERE lft BETWEEN @myLeft AND @myRight;UPDATE xp_subunit SET rgt = rgt - @myWidth WHERE rgt > @myRight;UPDATE xp_subunit SET lft = lft - @myWidth WHERE lft > @myRight;

我做错了什么吗...谢谢您的建议。

4

1 回答 1

1

$this->db->query($sql)旨在运行单个查询。

不支持单个调用中的多个查询。

于 2012-07-28T08:42:58.530 回答