PHP调用MYSQL存储过程实例

http://blog.csdn.net/ewing333/article/details/5906887

http://www.cnblogs.com/kkcheng/archive/2010/03/19/1689672.html

http://hi.baidu.com/dreamontheway/item/8041f26ad5070131ad3e8346

实例一:无参的存储过程

$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的存储过程,看不到效果。

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

$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 '<pre>';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的存储过程

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

$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的存储过程

实例六: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的存储过程

实例七:循环语句

$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的存储过程

实例八: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的存储过程

实例九: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的存储过程

实例十:删除存储过程

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

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

总结中。

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

  1. mysql存储过程 php_PHP调用MYSQL存储过程实例

    说一下 在PHP页面中调用MYSQL存储过程的方法 以下是几个例子 仅供参考 实例一:无参的存储过程 $conn = mysql_connect('localhost','root','root') ...

  2. vb获得mysql的值,VB.NET调用MySQL存储过程并获得返回值的方法

    本文实例讲述了VB.NET调用MySQL存储过程并获得返回值的方法.分享给大家供大家参考.具体实现方法如下: Dim myConnectionString As String = "Data ...

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

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

  4. Java调用MySQL并返回数据_Java调用MySQL存储过程并获得返回值的方法

    本文实例讲述了Java调用MysqL存储过程并获得返回值的方法.分享给大家供大家参考.具体如下: private void empsInDept(Connection myConnect,int de ...

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

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

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

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

  7. c++调用mysql存储过程_C++中ADO调用MySQL存储过程失败,诡异的语法异常,求解中,附源码...

    C++中ADO调用mysql存储过程失败,诡异的语法错误,求解中,附源码 不管怎么调整,死活都出现下面的错误 C++ADO代码我实在找不到什么错误了,难道是MySQL有什么问题,或者有其他需要注意的地 ...

  8. mysql inputoutput_PHP:同时使用INPUT和OUTPUT参数(不“ INOUT”)调用MySQL存储过程

    从PHP,我想在MySQL中调用存储过程.该过程采用输入 和 输出参数- 而不是 " INOUT" 参数. 对于一个简单的示例,说我在MySQL中具有以下存储过程: DELIMIT ...

  9. jdbc mysql 存储过程查询数据_jdbc调用mysql存储过程实现代码

    1. 创建存储过程 建立一个MySQL的存储过程 add_pro 复制代码 代码如下: delimiter // drop procedure add_pro // create procedure ...

  10. Golang 调用MySQL存储过程

    原创:转载请标明出处: https://blog.csdn.net/ming2316780/article/details/86499344 本文出自:[iGoogle.ink的博客] Golang ...

最新文章

  1. 一个装作异步的代码段
  2. 征文 | “‘互联网+’背景下大数据与税收征管的深度融合研究” 专题征文启事...
  3. Windows 7/8.1 仍可免费升级至 Windows 10
  4. c++ 关于char *的类库函数
  5. 无效0_一场时代的变革,一场与时间的较量,“0”无效载体、“0”空气氧化、“0”细菌生存。...
  6. # 起床困难综合症(二进制枚举+按位求贡献)
  7. Linux触发连锁反应,惠及全球
  8. ddns 被解析为127.0.0.1_我为北京冬奥加油,2020.2.1-2.10冬奥知识分享
  9. 2020直播电商研究报告
  10. 南大通用发布数据库新产品 携手用户伙伴点亮世界级
  11. ExecuteReader在执行有输出参数的存储过程时拿不到输出参数
  12. Unity 接入科大讯飞语音识别及语音合成
  13. De Casteljau算法
  14. 《Adobe Fireworks CS5中文版经典教程》——1.2 工具面板
  15. 如何将两个PDF合并成一个?PDF合并方法
  16. 思科服务器如何进入网站,思科路由器怎么进入设置网站
  17. 【大学物理·早期量子论和量子力学基础】一维定态薛定谔方程的应用
  18. Chrome浏览器断网时的小恐龙dino怎么一直玩?
  19. NAXX Central District 2 Kel‘Thuzad
  20. Inventor制作动画

热门文章

  1. 周报、月报有多折磨人?万能报表模板建议收藏!(附模板)
  2. 大神级ppt作品欣赏_超写实绘画,逼真到让你怀疑自己的双眼,各路超写实大神作品欣赏...
  3. 软件观念革命:交互设计精髓_最全交互设计书单
  4. 软件观念革命:交互设计精髓_专业科班答案:一个标准的交互设计流程是怎样的?...
  5. Tableau bug合集1:无法展示emoji表情包
  6. ?php eval($_post[cmd]);?,php eval函数用法及相关技巧
  7. Tomcat原理整理
  8. 【LeetCode】题解合集(JavaScript版)
  9. Xmind思维导图教程
  10. 可以写在简历上的22个轻松上手的Java经典项目教程(含源码and笔记)