Jump to content

Inregistrare in mysql cu ID unic?


Ciprian Iulian

Recommended Posts

  • Moderators

Da se poate, cu un auto-increment la coloana ID sau care vrei sa creasca automat.

Mai multe informatii aici:

http://www.w3schools.com/sql/sql_autoincrement.asp

https://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

In PhpMyAdmin se poate bifa sau alege optiunea de auto increment, parca e un checkbox care zice "AI"

  • Upvote 1

PHP Developer - Not available for freelancing right now

Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament

Link to comment
Share on other sites

  • Moderators

Normal coloana ID reprezinta un numar de la 1 la numere foarte mari in functie de cate randuri are baza de date.

Sa salvezi "pages" ca si ID unic nu e o idee buna, chiar deloc, pentru asta exita "primary key".

Verificarea e foarte simplu, odata ce incerci sa faci un insert nou, iti va spune ca este duplicat ace-l key si nu va face insertu. Query-ul de la functia cu care executi SQLu ar trebui sa-ti deie un rezultat intr-o variabila si dupa sa poti lucra cu variabila aia in functie daca e null, inseamna ca nu exista, daca returneaza o valoare, inseamna ca exista.

Treaba cu verificarea o mai poti face si printr-un try catch: http://www.w3schools.com/php/php_exception.asp

Si sigur mai exista metode, totu depinde ce functii folosesti sau daca folosesti PDO.

PHP Developer - Not available for freelancing right now

Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.