PHP mySQL - 将新记录插入到主键自动递增的表中 [英] PHP mySQL - Insert new record into table with auto-increment on primary key

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

问题描述

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

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天全站免登陆