php - Get the returned value from a prepared statement MySQL -
i trying make stored procedure want random value on database table name , other conditions of query dynamic (in stored proc params).
drop procedure if exists `myproc`; delimiter // create procedure `myproc`(in `tablename` varchar(50), in `isshow` tinyint(1), in `isadd` tinyint(1)) begin set @tname := tablename; set @isshow := isshow; set @isadd := isadd; set @pcode := ''; set @s = concat('select t.pcode ', @tname, ' t join (select round(rand() * (select max(idx) ', @tname,' )) id) x t.idx >= x.id , t.isshow = ', @isshow,' , t.isadd = ', @isadd, ' limit 1'); checkhand: while (!@pcode) prepare sp_query @s; execute sp_query; deallocate prepare sp_query; leave checkhand; end while ; end // delimiter ;
since use @var tablename, referred so , create sql query in concat
run stored procedure
. right now, tables has holes did while
loop until record pcode value.
my problem was, still returning blank pcode means @pcode var doesnt return value of query. don't have idea how store result of query ran in prepared statement variable , return result of stored procedure.
any do. please correct me. not pro sql user. thanks
my while loop supposed this:
while (!t.pcode) { // query , check if t.pcode return t.pcode }
Comments
Post a Comment