3

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

7

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();
answered Apr 13, 2015 at 0:40
1

We need to use $db->exec($query); instead of $db->query($query);. It returns the number of affected rows.

answered Dec 24, 2013 at 9:29
2
  • magento.stackexchange.com/questions/2905/… Commented Dec 24, 2013 at 9:30
  • There is no exec() method in Varien_Db_Adapter_Interface on my Magento 1.9.4.1 installation. Not sure if 1.7 had it? Commented Apr 5, 2019 at 8:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.