How can I save 2 values of a row in a table, simultaneously?
The table is called entity_export
and the columns are entity_id
and entity_type
.
Here is what I have:
Mage::getModel('xmlexport/export_entity')->setData('entity_id' => $orderNumber, 'entity_type' => 'order')->save();
but I get syntax error on the first =>
. And it looks like setData()
can save only 1 column value at a time, but I need them 2 simultaneously.
This is the direct SQL query execution that I was using before:
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = 'INSERT INTO `export_entity` (
`id` ,
`entity_id` ,
`entity_type`
)
VALUES (
NULL , "'.$orderNumber.'", "order"
)';
$connection->query($sql);
But I want to make it more elegant and injection proof. That's why I am trying to use the provided functionality by the framework, but I can't seem to handle it correctly. Any suggestions?
Best Answer
Try this:
You forgot to wrap your values inside an
array
.Here is how
Varien_Object::setData()
looks like