PHP mySQL - Insert new record into table with auto-increment on primary key

后端 未结 5 1237
予麋鹿
予麋鹿 2020-12-01 06:02

Wondering if there is a shorthand version to insert a new record into a table that has the primary key enabled? (i.e. not having to include the key column in the query) Lets

5条回答
  •  我在风中等你
    2020-12-01 06:52

    Use the DEFAULT keyword:

    $query = "INSERT INTO myTable VALUES (DEFAULT,'Fname', 'Lname', 'Website')";
    

    Also, you can specify the columns, (which is better practice):

    $query = "INSERT INTO myTable
              (fname, lname, website)
              VALUES
              ('fname', 'lname', 'website')";
    

    Reference:

    • http://dev.mysql.com/doc/refman/5.6/en/data-type-defaults.html

提交回复
热议问题