问题
I have a BIGINT field as an auto increment and primary key on a MySQL Innodb table, running MySQL Community Server 5.6.11.
After calling a basic INSERT statement, and then calling SELECT LAST_INSERT_ID(), I'm always returned 0, even though the INSERT statement was sucessful.
Any ideas why this might be happening.
UPDATE: Here is my table definition
CREATE TABLE `Booking` (
`BookingId` bigint(20) NOT NULL AUTO_INCREMENT,
`HotelId` int(11) NOT NULL,
`AgentId` int(11) NOT NULL DEFAULT '0',
`BookedOn` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`LastChangedBy` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`BookingId`)
ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=71 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
Here is my INSERT statement
INSERT INTO Booking
(
HotelId,
AgentId,
BookedOn,
LastChangedBy
)
VALUES
(
iHotelId,
iAgentId,
NOW(),
0
);
SELECT LAST_INSERT_ID() AS BookingId;
来源:https://stackoverflow.com/questions/17491849/select-last-insert-id-not-working-with-bigint-on-mysql-5-6-11