How to retrieve out parameter from mysqli stored procedure in php? -
i want access out parameter, mysqli database using stored procedures, , save in php variable printing message on web page.
my stored procedure is:
delimiter $$ create procedure insertuser (in _name varchar(50), in _username varchar(50), in _password varchar(50), in _email varchar(50), in _cellnumber int(11), in _estatename varchar(50), out _rply varchar(50)) begin declare count1 int; declare count2 int; declare varestateid int; declare _result varchar(50); select count(*) count1 users username = _username; select count(*) count2 users email = _email; if (count1+count2 < 1) insert users (username , passkey , email) values (_username ,_password,_email); insert estatedetails (estatename, estateownerusername) values (_estatename, _username); select estateid varestateid estatedetails estateownerusername = _username; insert usersdetail (username, name, cell1, estateid, accounttype) values (_username, _name, _cellnumber, varestateid, 'owner'); set _result = 'inserted'; else set _result = 'alreadyexist'; end if; set _rply = _result; end$$ delimiter;
my php side code calling stored procedure is: (incomplete code)
$db = new mysqli('localhost', 'root', '', 'estatelink'); $stmt=$db->prepare("call insertuser(?,?,?,?,?,?,?)"); $stmt->bind_param('ssssiss',$name, $username, $password, $email, $num, $estate_name, $rply); $stmt->execute(); $result= $rply;
note: query executing inserting data success. issue how can access out parameter in case $rply.
thanks in advance.
you not use output parameter. can set value, this:
set @_rply = 'foobar';
you can use it, this:
$db->multi_query( "call insertuser($name,$username,$password,$email,$cellnumber,$estatename,@_rply);select @_rply _rply" ); $db->next_result(); // flush null rs call $rs=$db->store_result(); // rs containing id echo $rs->fetch_object()->_rply, "\n"; $rs->free();
Comments
Post a Comment