Hakuna Matata
Hakuna Matata

Reputation: 11

MySQL or SQLITE to store who voted

I want to create a rating system (Ajax) with PHP for some images. Only registered users will be able to vote so i am going to store their id.

My question is should i create a table in MySQL where i will store the user id and photo id for all the images/ratings or should i write a script which will create a seperate SQLite file/database for EACH image where it will store the users' ids who voted.

I am going to use this table only to check if the user voted for this image or not. Total votes and score will be stored in another MySQL table.

Which would be faster?

MySQL (containing users' ids who voted from ALL the images)

image_id  |  user_id
---------------------
   114    |     12
   114    |     24
   114    |     53
   114    |     1

or

1 SQLite file foreach image rating

image_114.sqlite

user_id
-------
  12
  24
  53
  1

Upvotes: 1

Views: 144

Answers (1)

Eugen Rieck
Eugen Rieck

Reputation: 65274

My recommendation is to use the structure from your first example, but without a hard dependency on MySQL, so SQlite could still be used. Here is why:

  • I consider your second example abuse of a database. Assume, you want to show a page containing the highest ratest images .. how would you do so with the second approach?
  • The first approach seems quite fine to me, but since the structure is so trivial, why include a dependency on MySQL? Being able to run on "just about every" SQL makes the app a lot more portable

Upvotes: 1

Related Questions