我正在尝试使用基于 ZF2 的框架 Apigility 更新数据库中的一行。
我看到该行存在,检索它的内容,并更新对象。但是当我尝试执行 $table->update($arrayOfRowData);
时,我得到一个异常;
有关如何使用 Update()
的文档有点稀疏。我需要将 where=
子句放入吗?我是否需要让 where 子句与表的所有主键匹配?(主键使用 3 列)
try {
// if an entry already exists, update it
$existingRow = $this->currentEntryExists($ff_user_id, $subvalue);
if($existingRow != false ){
$fieldType = $this->transformer->mapField($key);
$existingRow[$fieldType] = $subvalue['value'];
$this->update($existingRow, $where = array('field_id' => $existingRow['field_id'], 'user_id' => $user_id, 'field_date' => $subvalue['dateTime']));
}else{
$fieldType = $this->transformer->mapField($key);
$dataArray = array('user_id' => $user_id,
'field_date' => $subvalue['dateTime'],
$fieldType => $subvalue['value']);
$result = $this->insert($dataArray);
}
} catch (Exception $e) {
$logger = $this->getServicesLogger();
$logger->err($e);
throw $e;
}
异常抛出:
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Internal Server Error",
"status": 500,
"detail": "Invalid magic property access in Zend\\Db\\TableGateway\\AbstractTableGateway::__get()"
最佳答案
原来我试图使用类中不存在的字段,这就是 Zend Framework 报告它的方式。
protected function getServicesLogger()
{
if (!$this->logger) { //this field didn't exist
$this->logger = new ApiLogger(get_class($this));
}
return $this->logger;
}
关于mysql - ZF2 aka Apigility 更新 SQL 数据库条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26196636/