好的,所以我正在做一个与上传文件和日期有关的项目。我的应用程序允许用户上传文件,他们可以看到他们上传的文件。如果需要,他们可以删除它们。一旦他们认为上传的文件很好,他们就可以完成它,这意味着他们无法删除上传的文件。另外,点击“结束”'按钮会将数据库中的状态更改为“已提交”#39;并加上时间戳。
到目前为止,我发现这两个错误。不知怎的,我在我的SQL中收到了这个错误:
更新leb2
。docs
AS Doc
设置Doc
。status
="已提交",
Doc
。datesubmitted
= 2015-02-14 14:46:21
在Doc
。schoolId
= 15
错误:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MySQL服务器版本相对应的手册,以便在Doc
附近使用正确的语法。schoolId
= 15'在第1行
这些是我的代码:
public function finalize_init(){
$this->layout = 'school';
$id = $this->request->params['pass'][0];
$this->Doc->id = $id;
$this->Doc->updateAll(array(
'Doc.status' => '"Submitted"',
'Doc.datesubmitted' => date('Y-m-d H:i:s')
), array(
'Doc.schoolId'=>$id
)
);
$this->redirect(array('action'=>'documents_init'));
}
这是我的数据库表:
CREATE TABLE `docs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`schoolId` int(11) DEFAULT NULL,
`datesubmitted` datetime DEFAULT NULL,
`status` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
我不确定日期的错误是什么。
我希望有人可以帮我解决这个问题。谢谢!
编辑:
这些在我的日志中
Nr Query Error Affected Num. rows Took (ms)
1 SELECT `School`.`schoolId`, `School`.`usersId`, `School`.`name`, `School`.`email`, `School`.`term`, `School`.`address`, `School`.`existing_or_new`, `School`.`province`, `School`.`region`, `School`.`type`, `School`.`telephone`, `School`.`fax`, `School`.`dean`, `School`.`dean_email`, `School`.`llm`, `School`.`dean_mobile`, `School`.`president`, `School`.`educational_attainment`, `School`.`status` FROM `leb2`.`schools` AS `School` WHERE `usersId` = 49 LIMIT 1 1 1 1
2 SELECT COUNT(*) AS `count` FROM `leb2`.`docs` AS `Doc` WHERE `Doc`.`schoolId` = 17 AND `Doc`.`status` = 'draft' 1 1 1
3 INSERT INTO `leb2`.`docs` (`schoolId`, `status`) VALUES (17, 'draft') 1 1 30
4 SELECT `Doc`.`id`, `Doc`.`schoolId`, `Doc`.`datesubmitted`, `Doc`.`status`, `School`.`schoolId`, `School`.`usersId`, `School`.`name`, `School`.`email`, `School`.`term`, `School`.`address`, `School`.`existing_or_new`, `School`.`province`, `School`.`region`, `School`.`type`, `School`.`telephone`, `School`.`fax`, `School`.`dean`, `School`.`dean_email`, `School`.`llm`, `School`.`dean_mobile`, `School`.`president`, `School`.`educational_attainment`, `School`.`status` FROM `leb2`.`docs` AS `Doc` LEFT JOIN `leb2`.`schools` AS `School` ON (`Doc`.`schoolId` = `School`.`schoolId`) WHERE `Doc`.`schoolId` = 17 AND `Doc`.`status` = 'draft' LIMIT 1 1 1 1
5 SELECT `Doc`.`id`, `Doc`.`schoolId`, `Doc`.`datesubmitted`, `Doc`.`status`, `School`.`schoolId`, `School`.`usersId`, `School`.`name`, `School`.`email`, `School`.`term`, `School`.`address`, `School`.`existing_or_new`, `School`.`province`, `School`.`region`, `School`.`type`, `School`.`telephone`, `School`.`fax`, `School`.`dean`, `School`.`dean_email`, `School`.`llm`, `School`.`dean_mobile`, `School`.`president`, `School`.`educational_attainment`, `School`.`status` FROM `leb2`.`docs` AS `Doc` LEFT JOIN `leb2`.`schools` AS `School` ON (`Doc`.`schoolId` = `School`.`schoolId`) WHERE `Doc`.`schoolId` = 17 AND `Doc`.`status` = 'draft' LIMIT 1 1 1 1
6 SELECT `Upload`.`iduploads`, `Upload`.`iddocs`, `Upload`.`dest`, `Upload`.`type`, `Upload`.`description`, `Doc`.`id`, `Doc`.`schoolId`, `Doc`.`datesubmitted`, `Doc`.`status` FROM `leb2`.`uploads` AS `Upload` LEFT JOIN `leb2`.`docs` AS `Doc` ON (`Upload`.`iddocs` = `Doc`.`id`) WHERE `Upload`.`iddocs` = 20 0 0 1
Nr Query Error Affected Num. rows Took (ms)
1 UPDATE `leb2`.`docs` AS `Doc` SET `Doc`.`status` = "Submitted", `Doc`.`datesubmitted` = 2015 WHERE `Doc`.`schoolId` = 17 AND `Doc`.`status` = 'draft'
答案 0 :(得分:1)
最终查询应该如下所示,
UPDATE leb2.docs AS Doc SET Doc.status = "Submitted", Doc.datesubmitted = '2015-02-14 14:46:21' WHERE Doc.schoolId = 15;
查询中缺少的是dateubmitted值的qoute
$date = date('Y-m-d H:i:s');
$this->Doc->updateAll(array(
'Doc.status' => '"Submitted"',
'Doc.datesubmitted' => "'{$date}'"
), array(
'Doc.schoolId'=>$id
)
);
实现查询, datesubmitted值应该用double qoute和single qoute括起来 “ '{$日期}'”