I'm having trouble figuring out how to get the number of affected rows from an update query in Drupal.
I have a form where users can update their profile details. Now, not every user is going to update everything from their profile. They may just update one field or two.
How do I account if there was a change or not and check for the affected rows?
This is the code I am running.
$update_query = $db->update('TABLE NAME')
->fields([
'uid' => $uid,
'name_of_user' => $name,
'url' => $url,
'website' => $website,
'industry' => $industry,
'company_size' => $companySize,
'company_type' => $companyType,
'headquarters' => $headquarters,
'founded' => $founded,
'page_picture' => $upload_picture,
'tagline' => $tagline,
'updated_at' => $time,
])
->condition('uid', $uid);
$affectedRows = $update_query->execute()->rowCount();
return new AjaxResponse($affectedRows);
The code doesn't return anything. I even checked the network tab and there's nothing displayed in the response tab. I should be getting back either 0 or 1. Am I missing something?