PHP 代码:php 存储过程调用实例代码
php 存储过程调用举例,供大家学习参考
代码如下:
//比如要调用的存储过程为 gxtj(a,b)
$db
=
new
mysqli("localhost","ssss","aaaaa","bbbb");
mysqli_query(
$db
,"SET NAMES utf8");
$result
=
$db
->query("call gxtj($year,$jd)");
// gxtj 是 mysql
的存储过程名称 [color=gray]
[/color]
while
(
$row
=
$result
->fetch_array(MYSQLI_ASSOC))
//
完成从返回结果集中取出一行
{
while
(
$key
=key(
$row
)){
//
依次取得字段名
$value
=current(
$row
);
//
依次取得字段值
}
}
实例一:无参的存储过程
代码如下:
$conn
= mysql_connect('localhost','root','root')
or
die
("数据连接错误!!!");
mysql_select_db('test',
$conn
);
$sql
= "
create procedure myproce()
begin
INSERT INTO user (id, username, sex) VALUES (NULL, 's', '0');
end
;
";
mysql_query(
$sql
);
//创建一个 myproce 的存储过程
$sql
= "call test.myproce();";
mysql_query(
$sql
);
//调用 myproce 的存储过程,则数据库中将增加一条新记录。
实例二:传入参数的存储过程
代码如下:
$sql
= "
create procedure myproce2(in score int)
begin
if
score >= 60 then
select 'pass';
else