I'm using mysql database in PHP via PDO as an interface. I need to get the values of row matched and changes of the table when I apply update or delete query. Let's say for example, I applied this sql statement
UPDATE user SET country = 'UK' WHEN country = 'United Kingdom'
I used PDO::rowCount()
to detect the numbers of affected row. The problem is that if user (accidentally or intentionally) try to update the details by providing the same values (for eg.
UPDATE user SET first_name='Bob' WHEN first_name='Bob'
it returns 0 since it doesn't change anything to the database. But, if first_name='Bob'
does not exist in the database, PDO still returning 0. I know I can use PDO::MYSQL_ATTR_FOUND_ROWS
to get numbers of matched row instead of numbers of affected row. But, i need both (matched rows, affected row or changes) to differentiate between if the record does not exist or if the query didn't update anything.
Is there any way to do it??
Is there any alternative to get the same info like mysql->info
just like in this link with PDO??