简体   繁体   English

CodeIgniter-MySQL错误1064(更新table1内部联接table2(…))

[英]CodeIgniter - MySQL Error 1064 (Update table1 inner join table2(…))

Is now 6am in the morning and i'm still struggling to execute a query with the CodeIgniter PHP framewok. 现在是早上6点,我仍在努力使用CodeIgniter PHP framewok执行查询。 Hope you guys can help me 希望你们能帮助我

Code: 码:

$query='
UPDATE `STUDY_LIST_AUX`
INNER JOIN `study_report` 
ON `STUDY_LIST_AUX.study_iuid`=`study_report.study_iuid`
SET `STUDY_LIST_AUX.report_date`=DATE_FORMAT(`study_report.report_date`,\'%Y-%m-%d %h:%i:%s\'), `STUDY_LIST_AUX.report_status` = `study_report.report_status`
';

if ($this->db->query($query))
{
        echo "True!<br><br>";
}
else
{
        echo "False<br><br>";
};

Error: 错误:

A Database Error Occurred 发生数据库错误

Error Number: 1064 错误号:1064

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE STUDY_LIST_AUX INNER JOIN study_report ON `STUDY_LIST_AUX.study_iu' at line 22 检查与您的MySQL服务器版本相对应的手册,以找到在'UPDATE STUDY_LIST_AUX INNER JOIN study_report ON'STUDY_LIST_AUX.study_iu'处附近使用的正确语法

I've tried everything, backticks, normal ticks, quote marks, but the error persists. 我已经尝试了所有方法,包括反引号,正常刻度线,引号,但错误仍然存​​在。 On phpmyadmin the query run successfully. 在phpmyadmin上,查询成功运行。

Any suggestions or ideas will be much appreciated 任何建议或想法将不胜感激

Thanks in advance guys :) 在此先感谢大家:)

try this. 尝试这个。 use double quote so you don't have to worry the quote inside 使用双引号,所以您不必担心里面的引号

$query="UPDATE STUDY_LIST_AUX
INNER JOIN study_report 
ON STUDY_LIST_AUX.study_iuid = study_report.study_iuid
SET STUDY_LIST_AUX.report_date = 
DATE_FORMAT(study_report.report_date,'%Y-%m-%d %h:%i:%s'), 
STUDY_LIST_AUX.report_status = study_report.report_status";

You have some syntax issue in the query ex: 您在查询ex中有一些语法问题:

 `STUDY_LIST_AUX.study_iuid` 

If you are using backticks then it should be as 如果您使用反引号,则应为

`STUDY_LIST_AUX`.`study_iuid`

The correct query should be 正确的查询应该是

$query = "
update `STUDY_LIST_AUX` sla
join `study_report`  sr on sr.study_iuid = sla.study_iuid
set 
sla.report_date = date_format(sr.report_date,'%Y-%m-%d %h:%i:%s'),
sla.report_status = sr.report_status
";

You can update your query code using this below Active Record code 您可以使用以下Active Record代码来更新query代码

$data = array('s.report_date' => 'DATE_FORMAT(`study_report.report_date`,\'%Y-%m-%d %h:%i:%s\')','s.report_status' => 'sr.report_status');
$this->db->update('STUDY_LIST_AUX s JOIN study_report sr on s.study_iuid = sr.study_iuid',$data);

This'll help you... 这会帮你...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM