说一下 在PHP页面中调用MYSQL存储过程的方法 以下是几个例子 仅供参考

实例一:无参的存储过程

$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

select 'no';

end if;

end;

";

mysql_query($sql);//创建一个myproce2的存储过程

$sql = "call test.myproce2(70);";

mysql_query($sql);//调用myproce2的存储过程,看不到效果,可以在cmd下看到结果。

实例三:传出参数的存储过程

$sql = "

create procedure myproce3(out score int)

begin

set score=100;

end;

";

mysql_query($sql);//创建一个myproce3的存储过程

$sql = "call test.myproce3(@score);";

mysql_query($sql);//调用myproce3的存储过程

$result = mysql_query('select @score ;');

$array = mysql_fetch_array($result);

echo '

';print_r($array);

实例四:传出参数的inout存储过程

$sql = "

create procedure myproce4(inout sexflag int)

begin

SELECT * FROM user WHERE sex = sexflag;

end;

";

mysql_query($sql);//创建一个myproce4的存储过程

$sql = "set @sexflag = 1";

mysql_query($sql);//设置性别参数为1

$sql = "call test.myproce4(@sexflag);";

mysql_query($sql);//调用myproce4的存储过程,在cmd下面看效果

实例五:使用变量的存储过程

$sql = "

create procedure myproce5(in a int,in b int)

begin

declare s int default 0;

set s=a+b;

select s;

end;

";

mysql_query($sql);//创建一个myproce5的存储过程

$sql = "call test.myproce5(4,6);";

mysql_query($sql);//调用myproce5的存储过程,在cmd下面看效果

实例六:case语法

$sql = "

create procedure myproce6(in score int)

begin

case score

when 60 then select '及格';

when 80 then select '及良好';

when 100 then select '优秀';

else select '未知分数';

end case;

end;

";

mysql_query($sql);//创建一个myproce6的存储过程

$sql = "call test.myproce6(100);";

mysql_query($sql);//调用myproce6的存储过程,在cmd下面看效果

实例七:循环语句

$sql = "

create procedure myproce7()

begin

declare i int default 0;

declare j int default 0;

while i<10 do

set j=j+i;

set i=i+1;

end while;

select j;

end;

";

mysql_query($sql);//创建一个myproce7的存储过程

$sql = "call test.myproce7();";

mysql_query($sql);//调用myproce7的存储过程,在cmd下面看效果

实例八:repeat语句

$sql = "

create procedure myproce8()

begin

declare i int default 0;

declare j int default 0;

repeat

set j=j+i;

set i=i+1;

until j>=10

end repeat;

select j;

end;

";

mysql_query($sql);//创建一个myproce8的存储过程

$sql = "call test.myproce8();";

mysql_query($sql);//调用myproce8的存储过程,在cmd下面看效果

实例九:loop语句

$sql = "

create procedure myproce9()

begin

declare i int default 0;

declare s int default 0;

loop_label:loop

set s=s+i;

set i=i+1;

if i>=5 then

leave loop_label;

end if;

end loop;

select s;

end;

";

mysql_query($sql);//创建一个myproce9的存储过程

$sql = "call test.myproce9();";

mysql_query($sql);//调用myproce9的存储过程,在cmd下面看效果

实例十:删除存储过程

mysql_query("drop procedure if exists myproce");//删除test的存储过程

实例十:存储过程中的游标

总结中。

mysql存储过程 php_PHP调用MYSQL存储过程实例相关推荐

  1. jsp实现mysql存储过程_JSP调用MySQL存储过程收藏

    JSP调用MySQL存储过程收藏 1使用不带参数的存储过程 使用 JDBC 驱动程序调用不带参数的存储过程时,必须使用 call SQL 转义序列.不带参数的 call 转义序列的语法如下所示: {c ...

  2. hql调用mysql存储过程_hibernate调用mysql存储过程

    在mysql中创建两个存储过程,如下: 1.根据id查找某条数据: 1 CREATE PROCEDURE `findEmpById`(IN id INTEGER(11))2 begin3      s ...

  3. hibernate mysql 存储过程_hibernate调用mysql存储过程

    hibernate调用mysql存储过程 在最近的项目中,碰到一小段数据库数据分析的程序,需要结合多张表联合查询或涉及到子查询,项目主要采用的java ee开发,使用了hibernate框架,由于这些 ...

  4. go mysql存储过程_Golang 调用MySQL存储过程

    Golang 调用MySQL存储过程 最近写项目发现,很多逻辑业务的实现,写到数据库的存储过程中,然后调用,真的非常方便.后端代码量大大减少,最重要的是性能高,速度快! 引用说明:项目使用数据库ORM ...

  5. C mysql带参数存储过程_C# 调用Mysql 带参数存储过程

    使用C#调用Mysql 带参数的存储过程: 1.创建带参数的存储过程:USP_Temp_Test 2.两个参数:IN 参数为 P_XML , OUT 参数为 P_ErrorOut 3.C#代码调用该存 ...

  6. pb 调用mysql过程_pb调用mysql函数或存储过程异常

    pb调用mysql函数或存储过程异常.尤其是mysql函数带传入传出参数时,pb调用时候无法正常执行,提示SQLSTATE=37000错误. 在pb程序中正常更新mysql表中字段或读取mysql表中 ...

  7. c#调用oracle存储过程,c#调用oracle存储过程

    c#调用oracle存储过程 CREATE OR REPLACE PACKAGE pkg_tableType IS type Tabletype is ref cursor; PROCEDURE SP ...

  8. java调用存储过程 oracle_java调用oracle存储过程

    java调用oracle存储过程 java代码 Map param = new HashMap(); param.put("in_str", "1,2,3,4" ...

  9. java调用存储过程sqlserver_Java调用SqlServer存储过程怎么实现 | 学步园

    在使用Java开发时,经常会遇到调用SqlServer存储过程的问题.下面学步园小编来讲解下Java调用SqlServer存储过程怎么实现? Java调用SqlServer存储过程怎么实现 1.数据库 ...

最新文章

  1. 2021中科院院士候选名单出炉:清华胡事民、南大周志华等人在列
  2. boost::mpl::integral_c用法的测试程序
  3. leetcode 171. Excel表列序号
  4. IEC 6-1131/3的5种标准编程语言
  5. [原创]FineUI秘密花园(二十七) — 窗体控件概述(上)
  6. 大数据时代,怎么做全渠道的营销
  7. python之用循环实现五子棋小程序
  8. windows2016安装.netFramework 3.5
  9. Unity3d发布web版无法连接数据库
  10. html 自动完成,如何指定 form或 input元素是否应在HTML中启用自动完成功能?
  11. wait 和 sleep 区别
  12. OpenSSL SSL_connect: Connection was reset in connection to github.com:443
  13. codejock Toolkit Pro for Visual C++ MFC 零售版
  14. Java设计模式-单例模式实际应用场景
  15. 自制题库答题考试软件小程序开发,把题库导入小程序里,javascript小程序
  16. 道德经和译文_道德经 - 道德经全文及译文 - 道德经全文 - 老子道德经
  17. MYSQL从简单查询到高级查询(一)
  18. 一名爱折腾人士的Apps for iPhone分享
  19. oracle+rac+ogg部署,RAC环境下配置OGG同步
  20. jQuery自定义插件

热门文章

  1. ps cs6 磨皮插件_PS后期磨皮插件美颜润肤如此简单,效果比DR3要好
  2. win10 本地升级和系统覆盖更新教程
  3. 软件著作权 开源框架_开源软件分享-基于.net core 3.1的快速开发框架
  4. php django mysql配置文件_Mysql学习Django+mysql配置与简单操作数据库实例代码
  5. c语言error c4430,error C4430: 缺少类型说明符 - 假定为 int。 异常怎么解决
  6. c语言中 d的作用,C语言中%d,%o,%f,%e,%x的意义
  7. submit按钮html,html的两种提交按钮submit和button
  8. c语言ut8,C语言使用utlist实现的双向链表
  9. 广数系统980tdb系统说明书_汽车离合操纵系统随车检测工具使用说明书
  10. 修补分支提交注意事项