$mysqli = new mysqli("localhost", "username", "password", "database_name"); $user_id = 123; // Verify user identity before proceeding with deletion $query = "DELETE FROM users WHERE id = $user_id"; $result = $mysqli->query($query); if ($result) { echo "User deleted successfully"; } else { echo "Error deleting user"; }
$client = new MongoDB\Client("mongodb://localhost:27017"); $usersCollection = $client->database_name->users; $user_id = "123"; // Verify user identity before proceeding with deletion $result = $usersCollection->deleteOne(['_id' => new MongoDB\BSON\ObjectID($user_id)]); if ($result->getDeletedCount() > 0) { echo "User deleted successfully"; } else { echo "Error deleting user"; }Package/Library: For both examples, the package/library used is dependent on the type of database being used. The mysqli library is commonly used for MySQL databases, while the MongoDB PHP library is used for MongoDB databases.