phpmysqlsystemcommentspicturegallery

mysql php commenting system: new database or looping through ids?


I want to make a picture website with a mysql php commenting system for each picture. Now, I can do two things: 1) use a new database for each picture or 2) use a single database + an id for each picture. The problem with the latter is that I need to loop the whole database everytime I want to find the comments for a picture. What's the most obvious way to handle this?


Solution

  • With very few exceptions you will put all of the things in a single database. The only reason for using multiple databases is extreme scaling.

    You won't have to "loop" through the database if your tables are properly indexed. You can fetch records like this:

    SELECT * FROM images WHERE id=192
    

    This will retrieve one record if present.

    If you're a little wobbly on SQL, then you'll either need to read up on that, or use a document store that doesn't require it.