MySQL/PHP:
For a query with multiple statements, which deletes rows in four different tables, I want to know the combined number of affected rows. The PHP manual says I'll only get the result from the last 'operation', which suggests it will only tell me how many rows were affected by the last of the DELETE statements. How to get around this?
$deleteContactSQL = "DELETE FROM `persons` WHERE `persons`.`id` = '$person' AND `owner = '$user' AND `userOrContact` = 'contact';
DELETE FROM `tabs` WHERE `person` = '$person' AND `ownerIdentity` = '$user' AND `selfOrOther` = 'other';
DELETE FROM `tabAccess` WHERE `person`= '$person' AND `givenToIdentity` = '$user';
DELETE FROM `personAccess` WHERE `viewedPerson` = '$person' AND `viewerIdentity` = '$user';
;";
include $_SERVER['DOCUMENT_ROOT'].'/goalview/includes/db.inc.php';
$deleteContacts = mysqli_query($link, $deleteContactSQL);
$success = mysqli_affected_rows($link);
Something like this maybe?
Here is a compact, procedural-style mysqli_multi_query() solution for counting combined affected rows:
Alternatively, this group of queries may be a good candidate for some TRIGGERs in the
persons
table.I'd be doing it like this, but, I do like to keep things simple which not everyone can appreciate ;)
You can use this method too if you must : http://php.net/manual/en/mysqli.multi-query.php