CodeIgniter - 错误编号:1146(在执行“CREATE TABLE”命令后表不存在) [英] CodeIgniter - Error Number: 1146 (Table doesn't exist after execute a "CREATE TABLE" command)
问题描述
我昨天在CodeIgniter上发布了一个关于mySQL更新语法的问题:
CodeIgniter - MySQL Error 1064更新table1 inner join table2(...))
I've posted yesterday an issue with an mySQL update syntax on CodeIgniter in here: CodeIgniter - MySQL Error 1064 (Update table1 inner join table2(...))
但现在我解决了这个问题后,另一个出现了。现在更新查询不知道新创建的表。
But now after I solved that problem, another one come up. Now the update query doesn't know the new created table. But if I change to a select statement, it works smoothly.
因为这个原因,我决定发布完整的脚本。
For that reason I've decided to post the full script.
代码:
<?php
$this->load->database();
$query_tbaux='CREATE TABLE IF NOT EXISTS STUDY_LIST_AUX AS (
SELECT DISTINCT p.pat_id, p.pat_custom1 age, p.pat_name,
p.pat_sex, s.study_iuid, p.pat_birthdate, s.accession_no,
s.study_datetime date_s, s.study_desc, s.mods_in_study, s.pk,
c.institution, s.study_block, s.study_urgent,
\'0000-00-00 00:00:00\' AS \'report_date\', \'{null}\' AS \'report_status\',
s.study_tipo,
s.study_src,
s.study_consulta
FROM study s
INNER JOIN patient p ON s.patient_fk = p.pk
INNER JOIN series c ON c.study_fk = s.pk
INNER JOIN rel_users_hosp u ON u.hosp_id = c.institution
WHERE s.study_datetime >= \'2015-04-26 00:00:00\'
AND s.study_datetime <= \'2015-04-30 23:59:59\'
AND s.study_iuid IS NOT NULL
AND u.user_id = \'admin\'
)';
if ($this->db->query($query_tbaux))
{
echo "Q True!<br><br>";
$data = array(
'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',
);
$this->db->update('STUDY_LIST_AUX, study_report', $data, array('STUDY_LIST_AUX.study_iuid'=>'study_report.study_iuid'));
}
else
{
echo "Q False<br><br>";
};
?>
显示/错误:
Q True!
Q True!
发生数据库错误
错误号码:1146
表'pacsdb.STUDY_LIST_AUX,
Table 'pacsdb.STUDY_LIST_AUX,' doesn't exist
UPDATE STUDY_LIST_AUX,
study_report
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'WHERE
code>。
study_iuid
='study_report.study_iuid'
UPDATE STUDY_LIST_AUX,
study_report
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' WHERE
STUDY_LIST_AUX
.study_iuid
= 'study_report.study_iuid'
我已经检查phpmyadmin刷新页面后,表真的存在,它包含select语句的数据。你能告诉我什么错误吗?
I've checked phpmyadmin after refresh the page and the table really exists and it contains the data from the select statement.Can you please tell me what mistake I did?
推荐答案
这可能会导致您真正的问题。在您的表名称后移除,study_report
。尝试
This may cause you real problem.Remove ,study_report after your table name.Try it
$this->db-
>update('STUDY_LIST_AUX',
$data,
array('STUDY_LIST_AUX.study_iuid'=>
'study_report.study_iuid'));
这篇关于CodeIgniter - 错误编号:1146(在执行“CREATE TABLE”命令后表不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!