PHP:唯一标识符

发布于 2024-08-23 09:31:20 字数 273 浏览 1 评论 0原文

我将刚刚加载的图像的 id 'concat' 到 mysql 用户记录中,如下所示。

 Userid … Photos_ids
 12         1 2 5 7

而且这个photo_id应该是唯一的。 (创建唯一的文件名)。现在我从内存缓存中获取当前的最后一个 id。但据我了解,这并不是真正安全。

难道还有其他的想法吗? (我不会将任何其他记录添加到数据库中,因此只有当我为此添加一些其他特殊表时才能使用主键......这不是一个好主意)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天荒地未老 2024-08-30 09:31:20

为什么不使用 PHP 的 uniqid 函数?

Why not use PHP's uniqid function?

情深缘浅 2024-08-30 09:31:20

有两个表,将 id 列设为主键,并将 自动递增

示例:

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)
 );

在示例中,插入新图片会自动将 id 加 1。

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.

安穩 2024-08-30 09:31:20

有一个单独的图像表。

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 :)

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 :)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文