I am having trouble creating a confirmation that a delete was successful. Here is the code:
$conn = db_connect();
$result = $conn->query(“delete from products where sku=‘1234’”);
if (!$result) {
throw new Exception(‘Error’);
}
The code works perfectly to delete the product, but it never returns an error message if it is unable to delete the product (e.g. if the SKU doesn’t exist).
I found online that I should use mysql_affected_rows so I tried this without success:
$conn = db_connect();
$result = $conn->query(“delete from products where sku=‘1234’”);
if (mysql_affected_rows() == 0) {
throw new Exception(‘Error’);
}
The error I get is:
Warning: mysql_affected_rows() [function.mysql-affected-rows]: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) in /home/content/24/10297924/html/secure/user_auth_fns.php on line 188
Out of desperation I also tried mysql_affected_rows($result) and mysql_affected_rows($conn) but I get errors:
mysql_affected_rows() expects parameter 1 to be resource, boolean given…
or
mysql_affected_rows() expects parameter 1 to be resource, object given…
Since I am obviously not understanding how this works I figured someone here surely knows more than me and can help me out.
Thanks very much.