2010-02-03 2 views
3

나는 다음과 같은 실행하려고 할 때 아래의 문제에 실행 해요 : 나는 $ STORE_ID 에코 때PHP는 교리 마지막 식별자 문제

$store = new Store(); 
$store->url =$this->form_validation->set_value('website'); 
$store->save(); 
$store_id = $store->identifier(); 


Fatal error: Uncaught exception 'Doctrine_Connection_Exception' with message 'Couldn't get last insert identifier.' in /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php:932 Stack trace: #0 /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php(632): Doctrine_Connection_UnitOfWork->_assignIdentifier(Object(Category_store_assn)) #1 /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php(562): Doctrine_Connection_UnitOfWork->processSingleInsert(Object(Category_store_assn)) #2 /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php(81): Doctrine_Connection_UnitOfWork->insert(Object(Category_store_assn)) #3 /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Record.php(1691): Doctrine_Connection_UnitOfWork->saveGraph(Object(Category_store_assn)) #4 /home/yummm/public_html/system/application/controllers/auth.php(375): Doctrine_Reco in /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php on line 932 

, 그것은 어떤 문제없이 마지막 ID를 잡는 것 같다. ID가 제대로 전달되고 있는데도이 오류가 계속 발생하는 이유는 무엇입니까?

답변

-1

아마도 setTableDefinition() 메서드를 덮어 쓰면 id 속성에 대한 hasColum() 전화가 없습니다.

0

hasColumn() 내부의 기본 키 필드에 문제가 'autoincrement'=> true 인 것을 발견했습니다. 'autoincrement'=> false로 설정하면 문제가 사라집니다.

그러나 해당 테이블의 기본 키 필드는 자동 증가 필드입니다. 그리고 여전히 이상한 점이 있습니다. 다른 컴퓨터에서는 오류가 없습니다. 응용 프로그램과 데이터베이스는 모든 컴퓨터에서 동일합니다.

0

이제 PDO 개체의 lastInsertId() 메서드가 0을 반환하기 때문에 발견되었습니다. 문제는 PDO 드라이버에 있으며 Doctrine 버그가 아닙니다. PHP 또는 PDO 확장 프로그램을 다시 설치해야합니다. 또한 http://bugs.php.net/bug.php?id=33618을 참조하십시오.

+1

이 버그 보고서는 5 년간 폐쇄되었습니다. PDO 드라이버가 올바르게 작동해야합니다. – Thomas

2

열 정의 자체가 auto_increment로 설정되지 않았을 수 있습니다. 테이블 정의를 다음과 같이 확인하십시오 : (MySQL 가정)

DESCRIBE table_name; 

그리고 ID 필드가 auto_increment로 플래그되어 있는지 확인하십시오. 그렇지 않으면 Doctrine은 테이블의 마지막 식별자를 얻으려고 시도하지만 MySQL의 LAST_INSERT_ID() 함수에 auto_increment 컬럼 만 응답하기 때문에 실패합니다.

0

Store 테이블의 ID가 자동 증가로 설정되지 않은 것 같습니다.

$this->hasColumn('id', 'integer', 11, array(
    'primary' => true, 
    'autoincrement' => false) 
    ); 

또는 필요한 경우 ID의 자동 증가를 설정 :이 경우, hasColumn 기능에 사용되는 혼합 옵션 매개 변수에 의해 교리 기록 모델에 '말씀'해야합니다.

0

필자의 경우 PDO 드라이버 버그였습니다.

1

Doctrine 1.2와 같은 문제가 있습니다. 이것은 작동하지 않았다 :

$this->hasColumn('id', 'int', null, array(
    'primary'  => true, 
    'autoincrement' => true 
)); 

그리고이 한 짓 왜 차이를

$this->hasColumn('id', 'integer', 4, array(
     'type' => 'integer', 
     'length' => 4, 
     'unsigned' => true, 
     'primary' => true, 
     'autoincrement' => true, 
)); 

확실하지하지만 도움이되기를 바랍니다.