zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    Go语言环境配置 Sublime Text + GoSublime+ gocode + MarGo组合
    Java中string拼接,StringBuilder,StringBuffer和+
    java调优随记-java对象大小
    java调优随记-堆和栈
    java中一直说一个汉字使用两个字节,原来是不准确的
    kv存储对抗关系型数据库
    记一篇
    变态的静态资源缓存与更新
    git add shh public key
    hashmap 的最优访问
  • 原文地址:https://www.cnblogs.com/huixuexidezhu/p/5498906.html
Copyright © 2011-2022 走看看