Home > Backend Development > PHP Tutorial > 如何获取一条新纪录的自增项的值?

如何获取一条新纪录的自增项的值?

WBOY
Release: 2016-06-06 20:17:06
Original
1338 people have browsed it

定义表时是这样定义的:

<code>CREATE TABLE Room
(
    R_Id char(128) AUTO_INCREMENT PRIMARY KEY,
    R_Info char(128) NOT NULL
)</code>
Copy after login
Copy after login

如果我向表中插入一条记录:

<code>INSERT INTO Room (R_Info) VALUES ("123456")</code>
Copy after login
Copy after login

请问有什么好的方法获取刚才插入记录自增项R_Id的值?

回复内容:

定义表时是这样定义的:

<code>CREATE TABLE Room
(
    R_Id char(128) AUTO_INCREMENT PRIMARY KEY,
    R_Info char(128) NOT NULL
)</code>
Copy after login
Copy after login

如果我向表中插入一条记录:

<code>INSERT INTO Room (R_Info) VALUES ("123456")</code>
Copy after login
Copy after login

请问有什么好的方法获取刚才插入记录自增项R_Id的值?

<code>INSERT INTO Room (R_Info) VALUES ("123456");
SELECT last_insert_id();</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template