This question has already been answered:
Please tell me how you can get the id of the newly created record in the sql table using php. Create a record in the table, too, using php.
This question has already been answered:
Please tell me how you can get the id of the newly created record in the sql table using php. Create a record in the table, too, using php.
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
For mysql . Taken from php.net
<?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('ΠΡΠΈΠ±ΠΊΠ° ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΡ: ' . mysql_error()); } mysql_select_db('mydb'); mysql_query("INSERT INTO mytable (product) values ('kossu')"); printf("ΠΠ΄Π΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΎΡ ΠΏΠΎΡΠ»Π΅Π΄Π½Π΅ΠΉ Π²ΡΡΠ°Π²Π»Π΅Π½Π½ΠΎΠΉ Π·Π°ΠΏΠΈΡΠΈ %d\n", mysql_insert_id()); ?> For mysqli . Taken from php.net
<?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΡ */ if (mysqli_connect_errno()) { printf("Π‘ΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅ Π½Π΅ ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ΠΎ: %s\n", mysqli_connect_error()); exit(); } mysqli_query($link, "CREATE TABLE myCity LIKE City"); $query = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart', 617000)"; mysqli_query($link, $query); printf ("ID Π½ΠΎΠ²ΠΎΠΉ Π·Π°ΠΏΠΈΡΠΈ: %d.\n", mysqli_insert_id($link)); /* Π·Π°ΠΊΡΡΡΠΈΠ΅ ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΡ */ mysqli_close($link); ?> mysql question - Evgeny Nikolaevmysqli - teranSource: https://ru.stackoverflow.com/questions/897272/
All Articles