MYSQL存储过程

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);

posted on 2016-05-16 17:40  会学习的猪  阅读(139)  评论(0编辑  收藏  举报

导航