我面临一个奇怪的问题。我正在使用mysqli extension
php 并调用 mysql 中的存储函数,该函数在表中插入一些值,我将 user_id 字段留空,因为它是自动递增的,但是插入查询失败,说明我没有默认值对于 user_id ,这已经是一个自动增量字段..我正在发布存储的函数。
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE FUNCTION `ideaforum`.`login_handler` (
login ENUM('facebook','twitter','google','local'),
firstname VARCHAR(40),
middlename VARCHAR(40),
lastname VARCHAR(40),
gender ENUM('male','female'),
emailid VARCHAR(50),
remoteid VARCHAR(70)
)
RETURNS INT
BEGIN
DECLARE user_exists INT DEFAULT NULL;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000'
SET user_exists = FALSE;
SELECT user_id FROM user WHERE email=emailid
INTO user_exists;
IF user_exists = FALSE THEN
INSERT INTO user
(login_type,first_name,middle_name,last_name,gender,email,remote_id)
VALUES
(login,firstname,middlename,lastname,gender,emailid,remoteid);
INSERT INTO contact
(contact_type,contact_details)
VALUES("email",emailid);
SELECT user_id FROM user WHERE email = emailid INTO user_exists;
RETURN(user_exists);
ELSE
RETURN(user_exists);
END IF;
END