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.

5

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();
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.