I am using following update query,
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$query = UPDATE `catalog_product_entity_decimal` val SET val.value = '11'
WHERE val.attribute_id = 75 AND
val.entity_id = (select cv.entity_id from `catalog_product_entity` as cv where cv.sku = '25' limit 1)
$afected = $db->query($query);
How could I get the affected rows count from the above query?. I have already looked on the How do I get the MySQL affected rows using the Magento resource? - but those not works for me.
Kindly advice me on the above.
2 Answers 2
I couldn't find a lot of documentation on this, but this worked for me (Magento EE 1.10.1.1).
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$query = "UPDATE `catalog_product_entity_decimal` val SET val.value = '11'
WHERE val.attribute_id = 75 AND
val.entity_id = (select cv.entity_id from `catalog_product_entity` as cv where cv.sku = '25' limit 1)";
$result = $db->query($query);
// Get count of affected rows
$affected_rows = $result->rowCount();
We need to use $db->exec($query); instead of $db->query($query);. It returns the number of affected rows.
-
magento.stackexchange.com/questions/2905/…mymotherland– mymotherland2013年12月24日 09:30:20 +00:00Commented Dec 24, 2013 at 9:30
-
There is no
exec()method inVarien_Db_Adapter_Interfaceon my Magento 1.9.4.1 installation. Not sure if 1.7 had it?Anse– Anse2019年04月05日 08:44:53 +00:00Commented Apr 5, 2019 at 8:44