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

  • 相关阅读:
    html抽取文本信息-java版(适合lucene建立索引)
    【LeetCode with Python】 Sort List
    POJ 2533 Longest Ordered Subsequence(dp LIS)
    Activity 之间 传递 List 封装的对象或者对象
    mongo数据库--非关系型数据库
    cocos2d-x的声音控制
    CSDN博客积分规则
    怎样使用递归实现归并排序
    android中9-patch图片的使用
    Cocos2d-x-3.0环境搭建
  • 原文地址:https://www.cnblogs.com/huixuexidezhu/p/5498906.html
Copyright © 2011-2022 走看看