php - MYSQL function that includes multiple queries, insert and select -


how can make function in mysql database can include queries insert table1 , select or in table, , parameters in function value

delimiter $ create function registration(username varchar(15), password(15), level_user int(1), name varchar(30), email varchar(30), address varchar(50)) returns int begin  insert users(username, password, level_user, created, modified) values('username', 'password', 'level_user'); insert employes(name, email, adrress) values('name','email', 'address');  end $ 

apart single quote issue have not provided data type password, have specified more fields insert users providing in values, employes may typo, name in values employes not provided , should username , must provide return statement if don't intend use in code. fix code check user not exist , set return value meaningful can check post execution.

this code "works"

drop function if exists registration; delimiter $$   create function registration(username varchar(15), password varchar(15), level_user int(1), name varchar(30), email varchar(30), address varchar(50))  returns int  begin  insert users(name, password) values(username, password); insert e(name, email, address) values(username,email, address); return 12; end $$ delimiter ; 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -