0
In the MYSQL
I have a table of subscribers where the primary key is the registration number which is a column that has no auto-increment, I can’t change that. I made, in Codeigniter, a method that picks up the next id for insertion like this:
SELECT MAX(incricao)+1 AS inscricao FROM inscritos;
This is done in the same insertion, I already have the object ready, so I put this value in the object and insert it into the database and it works.
The question is whether there is a way to do this while inserting using the same codeigniter, php or sql. If there is not, by doing what I quoted I run the risk of two simultaneous registrations taking the same number of inscription?
If anyway you are manually incrementing numerically in 1, I do not see why not use auto-increment of the bank. And yes, the way you are doing you will get conflict problem of Keys yes. What is the reason of not using the bank?
– AlfredBaudisch
The database is from a school, this table is used by other applications, so I was not allowed to change it.
– Jandira
Since you cannot change the existing table, then create a table only for auto_increment and get the ID like this:
SELECT AUTO_INCREMENT
FROM information_schema.tables
WHERE table_name = 'nome_table_incrementadora'
AND table_schema = DATABASE( ) ;
– AlfredBaudisch
Or
SHOW TABLE STATUS LIKE 'nome_table_incrementadora'
– AlfredBaudisch