What way should i create my download counter database? MySQL PHP
I would like to create a download counter for my files. Here are my current table fields:
download_counter table
_______________________
ID - int(6) - AutoInc,
Product - varchar(128),
Version - varchar(128),
Date - date,
IP's - LONGTEXT
I am wondering if I should use my current table or should I use a more dynamic an开发者_运维技巧d flexible table, like this:
ID - int(11) - AutoInc,
Product - varchar(128),
Version - varchar(128),
Date - date,
IP - varchar(45)
I would actually normalize your table properly:
download_counter {
did,
prodid,
dldstamp,
ip
}
and follow that up with your product table:
product_table {
prodid,
version,
description,
url,
lastmodified,
etc;
}
And you would just do inserts on your download_counter upon download request, referencing the prodid, from your product_table.
Simple enough and easy to normalize. You would then manage your products/downloads in the separate table.
I'd store a record per hit, but make sure you place indexes on any and all columns you'll be using to run SELECT
queries on later.
Side note: If you want to store IP address in MySQL, you should take a look at the INET_NTOA
and INET_ATON
functions. They convert dotted notation IP address to 32 bit integers, allowing you to store the address in 4 bytes rather than 15 bytes. They must also be unsigned integers.
精彩评论