From the course: PHP: Object-Oriented Programming with Databases

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Delete a record

Delete a record - PHP Tutorial

From the course: PHP: Object-Oriented Programming with Databases

Start my 1-month free trial

Delete a record

- [Instructor] Now that we've talked about how to create, read, and update using the active record pattern, we have one more operation to talk about. And that is delete. Delete is by far the simplest of all the four major operations. We don't have to worry about getting any form data to submit to the database, and we don't have to worry about working with any data that we get back from the database. We just simply tell the database to delete a specific record, and it either does or it doesn't. It's that simple. Let's remind ourselves what an SQL delete statement looks like. It's also very simple. We just have DELETE FROM, and then the table name, and in this case, bicycles. And then we have to tell it how to find the record or records that it should delete. Most of time we just want to delete a single record, and we're going to use it's primary key, which is its id. So I have a WHERE clause, where id='1'. I'm putting that inside single quotes to help prevent SQL injection. And then…

Contents