xRobot
xRobot

Reputation: 26567

Delete a database record and associated image

I have a table of photos like this:

photo_id, photo_url, user_id

When I want to delete a photo, I need to delete the row in the table and the photo on the server. So to do this, I need to do 2 queries:

  1. A SELECT query to return the photo's url and delete it with unlink()
  2. a DELETE query to delete the row in the table

Is a simpler way to do this, perhaps using only one query?

Upvotes: 0

Views: 262

Answers (1)

Vish
Vish

Reputation: 4492

Your way the best way to do this....How can it be simpler....

Also, if your photos use ids then you may just delete the row instead of selecting the query to return to the photos URL. then if this is successful proceed with deleting the thumbnail

Upvotes: 2

Related Questions