码迷,mamicode.com
首页 > 数据库 > 详细

MYSQL存储过程

时间:2016-05-16 19:17:41      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:

1、无参的存储过程

 1)创建

  技术分享

 2)php调用

    $mysqli = new mysqli($host,$user,$psw,‘test‘);

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

    $mysqli->query($sql);

2、传入参数的存储过程

  1)创建

    技术分享

 2)php调用

    $mysqli = new mysqli($host,$user,$psw,‘test‘);

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

    $mysqli->query($sql);

3、传出参数的存储过程

  1)创建

    技术分享

 2)php调用

  $mysqli = new mysqli($host,$user,$psw,‘test‘);
  $sql = "call test.test1(@a)";
  $mysqli->query($sql);
  $result=$mysqli->query(‘select @a as a;‘);
  $a=$result->fetch_assoc();
  echo ‘<pre>‘;print_r($a[‘a‘]);

4、传出参数的inout存储过程

  1)创建

    技术分享

 2)php调用

      $sql = "set @sexflag = 2";
      $mysqli->query($sql);//设置性别参数为1
      $sql = "call test.test2(@sexflag);";
      $result=$mysqli->query($sql);
      $a=$result->fetch_assoc();
      echo ‘<pre>‘;print_r($a);

4、使用变量的存储过程

  1)创建

    技术分享

 2)php调用

       $sql = "call test.test3(1,3);";
       $result=$mysqli->query($sql);
       $a=$result->fetch_assoc();
      echo ‘<pre>‘;print_r($a);

4、使用CASE的存储过程

  1)创建

    技术分享

 2)php调用

       $sql = "call test.test4(‘0‘);";
       $result=$mysqli->query($sql);
       $a=$result->fetch_assoc();
      echo ‘<pre>‘;print_r($a);

5、使用WHILE的存储过程

  1)创建

    技术分享

 2)php调用

       $sql = "call test.test5();";
       $result=$mysqli->query($sql);
       $a=$result->fetch_assoc();
       echo ‘<pre>‘;print_r($a);

MYSQL存储过程

标签:

原文地址:http://www.cnblogs.com/huixuexidezhu/p/5498906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!