0

I am trying to add new rows in my mysql table using PDO object, but it is giving me automated insert ID.

I need to make primary key values like -

key_1, key_2, key_3... etc.

But for now it's giving me the primary key value as 1,2,3..

Please suggest me some help , thank you.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
La Reyna
  • 128
  • 2
  • 12
  • 5
    Don't bother. Use the auto-incremented value as the primary key and be happy that MySQL provides this functionality. – Gordon Linoff May 27 '18 at 14:54
  • 2
    Use AUTO_INCREMENT and add the "key_" prefix in your application layer (if necessary). – Paul Spiegel May 27 '18 at 14:56
  • 3
    Possible duplicate of [How to make MySQL table primary key auto increment with some prefix](https://stackoverflow.com/questions/17893988/how-to-make-mysql-table-primary-key-auto-increment-with-some-prefix) – Script47 May 27 '18 at 14:57
  • 3
    What's the need for this? Primary key values are internal to the database and application and should not be visible to the outside world. Their format is of no consequence. As long as they are unique, you are good. Now, if you still need an ID with a specific format, then this is probably NOT the primary key, but a secondary ID for communications or other purpose. – The Impaler May 27 '18 at 15:00

0 Answers0