Suppose in magento database I have created a new table called ‘jyoti’ having the following fields.I have shown here how to select insert update and delete data in magento database using query concept.

id = integer
title = varchar
content = varchar
status = enum,

I have a module having the model called ‘jyoti’

so I want to do MySQL operation in this table by following operations.like INSERT,UPDATE,DELETE,SELECT.

INSERT:

Here I am getting the value of title,content,status and I set all the values into an array called data like below.Also in magento structure. So.So I can do insert operation by save() method through my module ‘jyoti’.First I have to set the array value into my model then called the save method which will do the MySQL insert operation.

SELECT:

For select operation just simple do call getCollection() method in the model then surely you will get object variable of collection.So by moving around through foreach loop you will get all the data one by one.You can call your desire data with respect to column name.for example : I have title in my table ‘jyoti’.I have got the object of that table.I Can get title by simple calling getTitle() method.

That is $collection->getTitle();.Like ways

$collection->getContent();
$collection->getStatus();
$collection->getId();

UPDATE:

Suppose I am getting id from request and I want to update the details related to that id in database table.

or

If I want to update single data taht is I have title as testtitle and I want that as newstesttitle in my database then I can use the following method.

DELETE:

I have id on above request.I can simple delete related data from table ‘jyoti’.So please follow below process to do the delete operation.

Hope you enjoyed the article and don’t forget to share it.

How to select insert update and delete data in magento database
Tagged on:     

3 thoughts on “How to select insert update and delete data in magento database

  • September 5, 2014 at 3:10 am
    Permalink

    Great article .Keep it up

    Reply
  • September 1, 2015 at 4:28 am
    Permalink

    Good Morning Sir,

     

    I am beginner of Magento.  So please help me how to begin to learn magento. if any reference please send me link.

    Thank you..

    Reply
  • September 1, 2015 at 4:31 am
    Permalink

    How to create module in magento..for this operation

    Reply

Leave a Reply

Your email address will not be published.