PHP mySQL-在主键上自动增加新记录到表中 [英] PHP mySQL - Insert new record into table with auto-increment on primary key

查看:63
本文介绍了PHP mySQL-在主键上自动增加新记录到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否存在将新记录插入启用了主键的表中的速记版本? (即不必在查询中包含键列) 假设键列称为ID,其他列为Fname,Lname和Website

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 say the key column is called ID, and the other columns are Fname, Lname, and Website

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

推荐答案

使用DEFAULT关键字:

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')";

参考:

这篇关于PHP mySQL-在主键上自动增加新记录到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆