7.8. Removing Deleted Entries from the Database

You need to write your deleteEntry() function in functions.inc.php. This function needs to accept the entry URL as an argument, then place that URL into a DELETE query that removes a maximum of one entry from the entries table.

Your MySQL query should read like this:

DELETE FROM entries
WHERE url=?
LIMIT 1

After you prepare the statement for execution, you use your supplied URL to execute the argument. You can make sure that the function executes successfully by returning the value of $stmt->execute() as the return value of your function.

Add your deleteEntry() function below retrieveEntries() in functions.inc.php:

function deleteEntry($db, $url)
{
    $sql = "DELETE FROM entries
            WHERE url=?
            LIMIT 1";
    $stmt = $db->prepare($sql);
    return $stmt->execute(array($url));
}

You can now delete entries from the database. You can test this by creating a temporary entry (see Figure 7-5), then deleting it to see whether it is removed from the database and, therefore, from your entry list (see Figure 7-6).

Figure 7.5. A temporary entry created using the Post a New Entry link

Figure 7.6. The temporary entry has been deleted, so it is no longer available in the title summary

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.80.100