Magento : How to find out if a record already exists in a database or not ?

To check whether record exist in database or not, you can use following query:

$collection = Mage::getModel('sample/sample')->getCollection()->addFieldToFilter('field_name', $value_to_check)->getFirstItem();
   //executing this block if record found in database
   //executing this block if record not found in database

Tags:  ,


thedotwriter 01-02-2013, 23:28

It’s not working for me since the Sample model simply doesn’t exist on magento installation (1.7)… If this is what I think, it could be useful.

Can you tell me a little more about that model? I didn’t found anything after a quick search…


Alonzo 04-06-2013, 07:05

Hi there, just wanted to mention, I enjoyed this article.
It was helpful. Keep on posting!


Leave a Reply

+ nine = ten