D6 module https://www.drupal.org/project/uc_dependent_attributes is converted to D7 here: http://dupgrade.com/ and I found out db_affected_rows() was removed from D7.
I tried few codes, basically copy and paste, based on this answer db_affected_rows gives fatal error in drupal 7. Now I have a different error: Call to a member function rowCount() on a non-object.
Code which throws Call to undefined function db_affected_rows()
function uc_dependent_attributes_uc_product_adjustments_form_submit(&$form, &$form_state) { foreach ($form_state['values']['body'] as $value) { if (!$value['enabled']) { db_update('uc_dependent_attributes')->fields(array( 'enabled' => 0, ))->condition('nid', $form_state['values']['nid'])->condition('combination', $value['combo_array'])->execute(); if (!db_affected_rows()) { db_insert('uc_dependent_attributes')->fields(array( 'nid' => $form_state['values']['nid'], 'combination' => $value['combo_array'], 'enabled' => 0, ))->execute(); } } else { db_delete('uc_dependent_attributes')->condition('nid', $form_state['values']['nid'])->condition('combination', $value['combo_array'])->execute(); } } }
Changed: This gives 'Fatal error: Call to a member function rowCount() on a non-object' error.
function uc_dependent_attributes_uc_product_adjustments_form_submit(&$form, &$form_state) { foreach ($form_state['values']['body'] as $value) { if (!$value['enabled']) { $result = db_update('uc_dependent_attributes')->fields(array( 'enabled' => 0, ))->condition('nid', $form_state['values']['nid'])->condition('combination', $value['combo_array'])->execute(); $affected_rows = $result->rowCount(); if ($affected_rows!=0) { db_insert('uc_dependent_attributes')->fields(array( 'nid' => $form_state['values']['nid'], 'combination' => $value['combo_array'], 'enabled' => 0, ))->execute(); } } else { db_delete('uc_dependent_attributes')->condition('nid', $form_state['values']['nid'])->condition('combination', $value['combo_array'])->execute(); } } }
How can I change db_affected_rows() to D7 properly?