레코드를 삽입하기 전에 마지막으로 삽입 된 ID를 얻을 수있는 동작을 구현하려고합니다.삽입하기 전에 마지막 ID 가져 오기
액션은 기본적으로 마지막으로 삽입 된 ID를 얻은 다음 1을 추가하여 현재 데이터에 삽입 된 값을 사용합니다.
이 나는 입수했습니다 및 오류가 나는이
Catchable fatal error: Object of class Zend\Db\ResultSet\ResultSet could not be converted to string I do not know where am going wrong.
모든 무엇입니까 오류입니다
if($id == 0){
$data['course_code'] = $this->getLastID();
$this->tableGateway->insert($data);
}else{
if($this->getAlbum($id)){
$this->tableGateway->update($data, array('id' => $id));
}else{
throw new \Exception("Form id does not exist");//an error is thrown in case the id is not found
}
}
을 저장하기 전에 여기에 함수를 호출
//the action to get the last inserted id
public function getLastID(){
$lastcourseid = $this->tableGateway->select(function (Select $select){
$select->columns(array('id'));
$select->order('id ASC')->limit(1);
});
var_dump($lastcourseid);
return $lastcourseid;
}
을 얻고 얼마나 도움을 주시면 감사하겠습니다. 감사합니다
먼저 삽입 한 다음 ... id가 auto_incrementing 기본 키라고 가정하고 새로 제공된 id를 사용하십시오. – Orangepill