在我的情况下
symfony2
尝试在循环中刷新我的行,但是我收到了错误。
我错过了什么?
foreach ($request->request as $key => $val) {
$form_result->setTitle($request->request->get('form-title-title-12431243'));
$form_result->setFieldId($request->request->get('form-title-id-12431243'));
$form_result->setKey($key);
$form_result->setIp($request->getClientIp());
$form_result->setType($request->request->get('form-title-type-12431243'));
$form_result->setValue($val);
$em->persist($form_result);
$em->flush();
}
错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, type, field_id, ip) VALUES ('test', 'test', 'form-title-title-12431243', 't' at line 1
答案 0 :(得分:1)
答案 1 :(得分:1)
名为key
的列为reserved word in MySQL。避免使用保留关键字是一种很好的做法,但在必须使用它的情况下,请使用保留字引用来解决问题。