我有以下查询用于从预购遍历数据库中插入和删除记录。我正在使用 codeigniter 并且不知道如何在其中触发多个查询。我尝试了以下查询,但没有在 codeigniter 中正确触发并使用 phpmyadmin 正确触发。
将记录插入数据库的查询:
$level = $_GET['level'] + 1;
$rgt = $_GET['rgt'] + 1;
if ($_GET['level'] == 0) {
$sql = "UPDATE xp_subunit SET lft = lft+2, rgt=rgt+2 WHERE rgt > " . $_GET['rgt'] . "; ";
$sql .="INSERT INTO xp_subunit SET level=" . $level . ", lft =" . $_GET['rgt'] . ", rgt = " . $rgt . " , name = '" . $_GET['name'] . "', unit_id='" . $_GET['unit_id'] . "', description='" . $_GET['description'] . "';";
echo $sql;
} else {
$sql = "UPDATE xp_subunit SET rgt = rgt+2 WHERE rgt > " . $_GET['lft'] . "; ";
$sql .="INSERT INTO xp_subunit SET level=" . $level . ", lft =" . $_GET['rgt'] . ", rgt = " . $rgt . " , name = '" . $_GET['name'] . "', unit_id='" . $_GET['unit_id'] . "', description='" . $_GET['description'] . "';";
echo $sql;
}
echo $query = $this->db->insert($this->tablename, $sql);
从数据库中删除记录的查询:
$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; ";
echo $query = $this->db->mysqli_multi_query($sql);
以上查询有什么问题?