Tuesday 15 April 2014

php - How to get the value of id(primary key) in previous operation in MySQL -


I am using MySQL, I need to insert a line in the first row, so I entered the row id Have to get. The code looks somewhat like the following:

in mytable (column2, column3, column4) value ('value2', 'value3', 'value 4' ) Or die (mysql_error ());

column 1

primary key

And this is an auto-increment, how to get the value of

column 1

in the previous operation?

You can use Docs:

  & lt ;? Php $ link = mysql_connect ('localhost', 'mysql_user', 'mysql_password'); If (! $ Link) {die (Could not connect: 'Mysql_error ()); } Mysql_select_db ('mydb'); Mysql_query ("Include mytable (product) values ​​('kossu')"); Printf ("The last inserted record has an ID% d \ n", mysql_insert_id ()); ? & Gt;  

No comments:

Post a Comment