doumaogui5937 2013-05-06 10:00 采纳率: 100%
浏览 39
已采纳

mySQL CodeIgniter - 语法错误号码:1064 [关闭]

I'm trying to wrap my head around this and I can't seem to figure out how this query returns a syntax error. My knowlegde of mySQL is small as I'm just getting to grips with it.

This is the query I'm trying to execute:

function _delete_leaf_node($id){

$query ="";

$query .=" SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1";
$query .=" FROM pages";
$query .=" WHERE id =".$id.";";

$query .=" DELETE FROM pages WHERE lft BETWEEN @myLeft AND @myRight;";
$query .=" UPDATE pages SET rgt = rgt - @myWidth WHERE rgt > @myRight;";
$query .=" UPDATE pages SET lft = lft - @myWidth WHERE lft > @myRight;";    

$this->_custom_query($query);

}

This is the error I get returned:

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 pages WHERE lft = @myLeft UPDATE pages SET rgt = rgt + 1, lft = lft ' at line 1

I have checked if the right id is passed. Perhaps the variables are not set in the proper manner? I just don't know how one would check for that.

Any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dongzhang1864 2013-05-06 10:22
    关注
    function _delete_leaf_node($id){
    
        $query  =" SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1";
        $query .=" FROM pages";
        $query .=" WHERE id =".intval($id);
    
        $this->_custom_query($query);
    
        $this->_custom_query("DELETE FROM pages WHERE lft BETWEEN @myLeft AND @myRight");
        $this->_custom_query("UPDATE pages SET rgt = rgt - @myWidth WHERE rgt > @myRight");
        $this->_custom_query("UPDATE pages SET lft = lft - @myWidth WHERE lft > @myRight");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)