The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
I'm working on PHP'ing and MySQL'ing my website, but I'm a little unsure as to what I'm doing regarding my Database. You see, at the moment I'm making a small administration system which allows me to upload images and add them to my image table within the DB.
The thing I'm unsure about is creating a unique ID (or GUID), for each image, you see, at the moment, this is how I create my ID
$ID = createGUID($files[$x]);
function createGUID($filenames) {
//my first ever function, quite proud of it, unsure whether it's practical
$filenames = md5($filenames);
$id = $filenames;
return($id);
}
(To put you into the picture here, My program loops through every file within the image directory and add's it too the database, creating a new ID for each one)
As you can see, all it does it pass the file name from the loop into the function, md5's that string and returns it, ready to go into the DB. The benefit of this is the fact that it means the data cannot be entered into the database twice, becase the md5 ID's would match.
I was just wondering if this was OK, or does anyone have a more feasible idea?
Thanks
Maybe of no use to you in this situation but also look at
http://dev.mysql.com/doc/mysql/en/REPLACE.html
> You could set your Database ID to be an AUTO_INCREMENT value, it'll
> assign a unique ID for you.
Yep, that's no problem, but the thing is, say if I activated my "populate DB" button twice, it'd go through the directory twice, adding the same filename twice because the ID's would be unique
I'm working on PHP'ing and MySQL'ing my website, but I'm a little unsure as to what I'm doing regarding my Database. You see, at the moment I'm making a small administration system which allows me to upload images and add them to my image table within the DB.
The thing I'm unsure about is creating a unique ID (or GUID), for each image, you see, at the moment, this is how I create my ID
$ID = createGUID($files[$x]);
function createGUID($filenames) {
//my first ever function, quite proud of it, unsure whether it's practical
$filenames = md5($filenames);
$id = $filenames;
return($id);
}
(To put you into the picture here, My program loops through every file within the image directory and add's it too the database, creating a new ID for each one)
As you can see, all it does it pass the file name from the loop into the function, md5's that string and returns it, ready to go into the DB. The benefit of this is the fact that it means the data cannot be entered into the database twice, becase the md5 ID's would match.
I was just wondering if this was OK, or does anyone have a more feasible idea?
Thanks