MYSQL primary key is it possible to create an AUTO_INCREMENT fill mask?

2

I wonder if it's possible to create a primary key, aaa-0000 as a mask, and still be auto_increment , example aaa-0000, aaaa-0001, and so on. If so, how?

Thank you

    
asked by anonymous 20.06.2016 / 21:22

1 answer

1

Apply the mask at the time of the display.

$db = [conexao e leitura do banco];
foreach ($db as $v) {
    //iterando os dados extraídos do banco
    echo 'aaa-'.str_pad($v['id'], 4, '0', STR_PAD_LEFT).PHP_EOL;
}

(the above code is didactic, with illustrative purpose)

output:

id 1 will display: aaa-0001
id 10 will show: aaa-0010
id 100 will show: aaa-0100

See: str_pad ()

    
20.06.2016 / 22:59