我有一些代码:
$done_tasks = R::getCol('SELECT count(*) FROM tasks WHERE `status` = "done" AND id IN
(SELECT task_id FROM tasksemployess WHERE employee_id = ?)', array($_SESSION['employee']['id']));
$failed_tasks = R::getCol('SELECT count(*) FROM tasks WHERE `status` = "failed" AND id IN
(SELECT task_id FROM tasksemployess WHERE employee_id = ?)', array($_SESSION['employee']['id']));
$process_tasks = R::getCol('SELECT count(*) FROM tasks WHERE `status` = "in_process"
OR `status` = "cheking" OR `status` = "remaking" AND id IN
(SELECT task_id FROM tasksemployess WHERE employee_id = ?)', array($_SESSION['employee']['id']));
$avg_mark = R::getCol('SELECT avg(mark) FROM tasks WHERE id IN
(SELECT task_id FROM tasksemployess WHERE employee_id = ?)', array($_SESSION['employee']['id']));
R::exec('UPDATE FROM persresults SET done_tasks = ?, failed_tasks = ?, process_tasks = ?, avarage_mark = ?,
WHERE employee_id = ?',array($done_tasks[0], $failed_tasks[0], $process_tasks[0], $avg_mark[0], $_SESSION['employee']['id']));
除最后一个请求外的所有请求都返回一个数组,因此在上一个请求中,我将它们称为数组,似乎一切正确,但是:
根据结果更新SET done_tasks = 3,failed_tasks = 0, process_tasks = 0,avarage_mark = '67 .0000',WHERE employee_id = 19 An 发生错误:SQLSTATE [42000]:语法错误或访问冲突: 1064您的SQL语法错误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 接近'FROM persresults SET done_tasks = 3,failed_tasks = 0, process_tasks = 0,在第1行上显示为“
如您所见,插入的值会根据需要传递,但是由于某种原因会发生此错误。
答案 0 :(得分:1)
您不应该使用UPDATE FROM(只是UPDATE table_name),并且在更新之前WHERE之前有一个逗号错误
R::exec('UPDATE persresults
SET done_tasks = ?
, failed_tasks = ?
, process_tasks = ?
, avarage_mark = ?
WHERE employee_id = ?',array($done_tasks[0],
$failed_tasks[0],
$process_tasks[0],
$avg_mark[0], $_SESSION['employee']['id']));