删除数据库记录和关联的图像

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?

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