say have stored procedure in mysql below
-- ---------------------------- -- procedure structure usp_insert_user_basic_info -- ---------------------------- drop procedure if exists `usp_insert_user_basic_info`; delimiter ;; create definer=`root`@`localhost` procedure `usp_insert_user_basic_info`(in `user_first_name` varchar(200),in `user_last_name` varchar(200),in `user_password` text,in `user_dob` date,in `user_email` varchar(250)) begin #routine body goes here... insert `nuclear`.`user_basic_info` ( `user_email` , `user_password` , `user_first_name` , `user_last_name` , `user_dob`, `user_creation_time` ) values ( user_email, user_password, user_first_name, user_last_name, user_dob,now() ); select last_insert_id() ; end ;; delimiter ;
table
-- ---------------------------- -- table structure user_basic_info -- ---------------------------- drop table if exists `user_basic_info`; create table `user_basic_info` ( `user_id` int(11) not null auto_increment, `user_email` varchar(250) default null, `user_password` text, `user_first_name` varchar(200) default null, `user_last_name` varchar(200) default null, `user_dob` date default null, `user_creation_time` datetime default null, primary key (`user_id`), unique key `user_email` (`user_email`) ) engine=innodb auto_increment=36 default charset=latin1;
i can call php without problem
$resultusp = mysql_query($query) or die("error: " . mysql_error());
but returns 1 each successful insert. guess saying 1 row affected!
i want return last_insert_id
how it? way don't want add out parameter. mysql_insert_id returns 0
you can last insert id in sp:
declare lid int; set lid = last_insert_id();
Comments
Post a Comment