in my plugin I use an additional table. That table has an id, which is set to AUTO_INCREMENT. When I insert something in there, I do something like:

$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$query = 'INSERT INTO test (column1, column2) VALUES (3, 4)';

In this case the table test has also an id.
Is there a way I could get this id after I inserted it?

1 Answer 1


You can get it like this:


But you are doing it wrong.
You should have a model and a resource model that maps on your table and you should use the ORM to persist data.
Have something like this:

$model = Mage::getModel('[module]/test');
$model->setData(array('column1' => 3, 'column2' => 4 ));
$id = $model->getId();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.