How to create a primary key?

I want to create a primary key like this ...

http://www.example.com/download?d=NAPHMPWI

... i.e. ?d=NAPHMPWI.

How can i do this?

+3
source share
2 answers

Make the primary key an automatic incremental integer, as most databases support out of the box. Display it as a string for your URLs, translating it to base 36 (which uses the numbers 0-9 and AZ).

echo base_convert($id, 10, 36);

And convert the URLs to database identifiers by converting from base 36 to base 10:

$id = base_convert($url_key, 36, 10);
+6
source

If you want to create a primary key in a column char(for example, a parameter dfor a published link):

CREATE TABLE links (Url CHAR(8) NOT NULL, PRIMARY KEY(Url))
0
source

Source: https://habr.com/ru/post/1791824/


All Articles