0

在我的模型中,我具有以下功能:

function update_blog($data, $id){

   $id = $this->uri->segment(3);

$sql = "UPDATE database.newblog (name, address, email)
    SET (".$this->db->escape($data['name']).",
            ".$this->db->escape($data['address']).",
            '".$data['sEmail']."',
    WHERE id = ".$id."; ";

echo $sql;

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

}
}

当我将此查询直接放入 SQLyog 时,它会出现错误:

错误代码:1064 您的 SQL 语法有错误;

?

谢谢

4

1 回答 1

1

试试这个:

$sql = "UPDATE blogs.newblogsetup 
        SET `name`      = '".$this->db->escape($data['name'])."',
        `address`       = '".$this->db->escape($data['address'])."',
        `email`         = '".$data['sEmail']."',
        `nickname`      = '".$this->db->escape($data['nickname'])."',
        `region`        = '".$data['blogregion']."',
        `startdate`     = '".$startdate."',
        `blogtitle`     = '".$this->db->escape($data['blogtitle'])."',
        `timesperweek`  = '".$data['timesperweek']."',
        `profiletext`   = '".$this->db->escape($data['profiletext'])."',
        `abouttext`     = '".$this->db->escape($data['abouttext'])."',
        `status`        = '".$data['status']."',
        `userid`        = '".$data['userid']."'
        WHERE id        = ".$id."; ";

更好的使用Active Records

$this->db->where('id', $id)->update( 'newblogsetup', $data );
echo $this->db->last_query();die;
于 2013-10-22T13:30:49.933 回答