CodeIgniter更新语法?

时间:2014-04-26 17:32:53

标签: php mysql codeigniter

我正在尝试更新我的' HM_Jobs'数据库,据我可以从手册中看出这应该有效,但它没有更新数据库,有什么建议吗?

function amend_job($title,$description,$location,$date,$time,$pay,$jobcat,$job_id) //This function amends a job.//
{ 
    $amendJob=array(
    "JobTitle"=>$title,
    "JobDescription"=>$description,
    "JobLocation"=>$location,
    "JobDate"=>$date,
    "JobStartTime" =>$time, 
    "JobPay"=>$pay, 
    "JobCategory"=>$jobcat, 
    ); 


    $this->db->where('JobID', $job_id);
    $this->db->update('HM_Jobs', $amendJob);
} 

1 个答案:

答案 0 :(得分:0)

<强>型号:

建议:发送数组$data而不是分别发送每个值。

检查您是否完成了与我在下面所做的相同的操作 -

class Job_model extends CI_Model
{

    public $db;
    public function __construct()
    {
        parent::__construct();
        $this->db = $this->load->database('default',true);
    }

    public function amend_job($data, $job_id)
    {   
        $amendJob=array(
                          "JobTitle"=>$data['title'],
                          "JobDescription"=>$data['description'],
                          "JobLocation"=>$data['location'],
                          "JobDate"=>$data['date'],
                          "JobStartTime" =>$data['time'], 
                          "JobPay"=>$data['pay'], 
                          "JobCategory"=>$data['jobcat'] 
                    ); 

                    $this->db->where('JobID', $job_id);
                    $this->db->update('HM_Jobs', $amendJob);
    }
}


尝试调试:

1)打印传递给函数的值。

echo $job_id.'<br><pre>'; print_r($data);


2)如果值正确,请尝试打印查询。

echo $this->db->last_query();   // after update query