Reputation: 8387
I ‘concat’ an id of just loaded image into mysql user record like this.
Userid … Photos_ids
12 1 2 5 7
And this photo_id should be unique. (To create unique file name). Now I get a current last id from memcache. But it's not really safely, as far as I understand.
It there any other ideas? (I do not add any other records into db, so PRIMARY KEY can be used only if I'd add some else special table for this... It's not a good idea).
Upvotes: 2
Views: 411
Reputation: 317197
Have two tables, make the id column the Primary Key and Auto Increment
Example:
CREATE TABLE users(
id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
name CHAR(60) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE pictures (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
user_id MEDIUMINT NOT NULL
PRIMARY KEY (id)
);
In the example, INSERTing a new pictures would automatically increase the id by 1.
Upvotes: 1
Reputation: 3323
Have a separate table for images.
id (auto-increment)
image_url
..any other info you need about images
user_id (foreign key)
user id obviously shows which user is the owner of that image. It points to the id column of users table. Adjust according to your db model :)
Upvotes: 0