connect_error) { die("Connection failed: " . $conn->connect_error); } // SQL to delete a contact $sql = "DELETE FROM contacts WHERE id=1"; if ($conn->query($sql) === TRUE) { echo "Contact deleted successfully"; } else { echo "Error deleting contact: " . $conn->error; } $conn->close(); ?>
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // SQL to delete a contact $sql = "DELETE FROM contacts WHERE email='john@example.com'"; // use exec() because no results are returned $conn->exec($sql); echo "Contact deleted successfully"; } catch(PDOException $e) { echo $sql . "Both examples use package libraries for database connectivity, with the first example using MySQLi and the second example using PDO. MySQLi is a MySQL-specific library for PHP, while PDO is a database abstraction layer that supports multiple database systems, including MySQL.
" . $e->getMessage(); } $conn = null; ?>