delimiter // drop procedure if exists test; create procedure test(in user varchar(50),in pwd varchar(50)) beginset @sql = concat('select * from user where username=',user,' and password=',pwd); prepare stmt from @sql; execute stmt; deallocate prepare stmt; end; //mysql_query(call test('root','root'));
按楼上写的程序怎么SQL老是不执行呀?$sql1="delimiter // drop procedure if exists test; create procedure test(in user varchar(50),in pwd varchar(50)) beginset @sql = concat('select * from user where username=',user,' and password=',pwd); prepare stmt from @sql; execute stmt; deallocate prepare stmt; end; // "; $ree1=mysql_query($sq1); var_dump($ree1);
不能在PHP上执行吗?那还有什么用吗?
就算把drop procedure if exists test这句删了,还行不执行呢?老是失败,估计SQL错误?
CREATE
[DEFINER = { user | CURRENT_USER }]
PROCEDURE sp_name ([proc_parameter[,...]])
[characteristic ...] routine_body调用就像执行sql语句差不多
CALL sp_name(args)
delimiter //
drop procedure if exists test;
create procedure test(in user varchar(50),in pwd varchar(50))
beginset @sql = concat('select * from user where username=',user,' and password=',pwd);
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
end;
//mysql_query(call test('root','root'));
drop procedure if exists test;
create procedure test(in user varchar(50),in pwd varchar(50))
beginset @sql = concat('select * from user where username=',user,' and password=',pwd);
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
end;
//
";
$ree1=mysql_query($sq1);
var_dump($ree1);