0

I've following sql query to delete the nodes.

$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);

I tried this query in phpmyadmin it executes successfully and delete the node as desired. but when I'm converting it to codeigniter code it gives mysql syntax error like:

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;

Does I'm doing something wrong... thanks in adv.

J.K.A.
  • 7,272
  • 25
  • 94
  • 163

1 Answers1

1

$this->db->query($sql) is meant to run a single query.

Multiple queries in a single call are not supported.

Yan Berk
  • 14,328
  • 9
  • 55
  • 52