GetDotted Domains

Viewing Thread:
"Is this good practise (Databases)"

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.

Wed 22/09/04 at 22:11
Regular
Posts: 10,364
Hi there.

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
Wed 22/09/04 at 23:18
Regular
"Devil in disguise"
Posts: 3,151
I'm presuming you store the image file name in your DB. Set that field to be unique. If you try to reinsert the same file, the query will fail anyway, ie no duplicate filenames allowed. That way you can do as cjh suggested and use an auto_increment field for your id and gain yourself some far less cumbersome image ids.
Maybe of no use to you in this situation but also look at
http://dev.mysql.com/doc/mysql/en/REPLACE.html
Wed 22/09/04 at 22:26
Regular
"It goes so quickly"
Posts: 4,083
Ah, I see your point, in that case the way you've done it seems ok to me, though Turbo may have some advice, as I think he's in the deep end of PHP compared to me.
Wed 22/09/04 at 22:16
Regular
Posts: 10,364
cjh wrote:
> 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
Wed 22/09/04 at 22:13
Regular
"It goes so quickly"
Posts: 4,083
You could set your Database ID to be an AUTO_INCREMENT value, it'll assign a unique ID for you.
Wed 22/09/04 at 22:11
Regular
Posts: 10,364
Hi there.

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

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Very pleased
Very pleased with the help given by your staff. They explained technical details in an easy way and were patient when providing information to a non expert like me.
Excellent support service!
I have always found the support staff to provide an excellent service on every occasion I've called.
Ben

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.