加入多个表失败时更新

问题描述 投票:0回答:1

我试图使用连接更新两个表,我的Codeigniter模型代码在这里:

$patient_secondary = array(
    'vpd.patient_id'=>$data['patient_id'],
    'mpd.patient_id'=>$data['patient_id'],
    'vpd.reason'=> 'Death/Expiry',
    'vpd.status_' => 0,
    'mpd.status_' => 0,
);
$this->db->set($patient_secondary);
$this->db->where('`vpd`.`patient_id`', $data['patient_id']);
$this->db->where('`mpd`.`patient_id`', $data['patient_id']);
$this->db->update('volga_primary_patient_details  AS vpd JOIN master_patient_details AS mpd ON vpd.patiend_id = mpd.patient_id');

但是我收到以下错误:

A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.`patiend_id = mpd`.`patient_id` SET `vpd`.`patient_id` = '22', `mpd`.`patient_i' at line 1

UPDATE `volga_primary_patient_details AS vpd JOIN master_patient_details` AS `mpd ON vpd`.`patiend_id = mpd`.`patient_id` SET `vpd`.`patient_id` = '22', `mpd`.`patient_id` = '22', `vpd`.`reason` = 'Death/Expiry', `vpd`.`status_` = 0, `mpd`.`status_` = 0 WHERE `vpd`.`patient_id` = '22' AND `mpd`.`patient_id` = '22'


Line Number: 691
php mysql codeigniter
1个回答
0
投票

语法错误......仔细看看

... ON vpd`.`patiend_id = mpd`.`patient_id` SET ...
  • 在vpd之前缺少反引号
  • 在patient_id之后缺少反复
  • 在mpd之前缺少反击

唉,我不知道CodeIgniter如何创建查询..你的代码对我来说没问题(那里有反引号)

© www.soinside.com 2019 - 2024. All rights reserved.