¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita+ 1
Generate uniqe UID and store to mysql's table
I have a table that UID column name is its primary key and I use PDO to connect to mysql with PHP. How to generate a unique user id for any new user that has registered and store it(user id) to UID column in my sql? Please help me ☺
3 Respuestas
+ 9
Hamidreza Abolfathi Hey, I agree with Shudarshan Rai 👑 but you can still perform sql select to generate ID. I would use something like this
select isnull(max(cast(machines.ID as int)), 0) + 1
from dbo.machines machines
/*
Idea: New record will always get highest ID from table
1. select ID
2. select max ID to get latest number
3. avoid string value and cast it as intiger
4. handle null values with isnull
*/
+ 4
//Better then generating UID from code storing on database, checking if it's already exist, Do make a column of UID, type=Int and use A.I (auto increment). Whenever new user registers auto gives unique id
+ 1
Shudarshan Rai 👑 , r8w9
OK . Thanks for your answers.