Problem with last php doctrine id

I am trying to run the following:

$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

When I repeat $ store_id, it seems to grab the last id without any problems. Any idea why this error continues to grow even if the identifier is passed correctly?

+3
source share
7 answers

It is possible that the column definition itself is not configured as auto_increment. Check the table definition with: (assuming MySQL)

DESCRIBE table_name;

and make sure your ID field is marked as auto_increment. If it is not, Doctrine will try to get the last identifier for the table, but will fail, because only the auto_increment columns respond to the MySQL function LAST_INSERT_ID ().

+2

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,
));

, , , .

+1

, "" = > true hasColumn(). "" = > , .

. , . .

0

, , lastInsertId() PDO 0. , , PDO, Doctrine. PHP PDO. . http://bugs.php.net/bug.php?id=33618.

0

Your identifier from the Store table is probably not set to auto-increment. In this case, you need to “tell” it in the doctrine record model using the mixed option parameter in the hasColumn function:

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

Or, if necessary, configure the auto-increment of the identifier.

0
source

In my case, it was a PDO driver error.

0
source

You may have overwritten the method setTableDefinition(), and now not hasColum()for your attribute id.

-1
source

Source: https://habr.com/ru/post/1731145/


All Articles