zoukankan      html  css  js  c++  java
  • mysqli的增强功能

    批量执行sql语句

    批量执行dml语句
    基本语法
    $sqls="sql1.sql2.sql3...."
    mysqli::multi_query($sqls)
    案例:
    $mysqli=new mysqli("localhost","root","","test");
    if($mysqli->connect_error){
    die($mysqli->connect_error);
    }
    $sqls="insert into user1(name,password,email,age) values('宋江','aaa','aa@qq.com',45);";
    $sqls.="insert into user1(name,password,email,age) values('吴用','aaa','aa@qq.com',46);";
    $sqls.="insert into user1(name,password,email,age) values('李逵','aaa','aa@qq.com',47);";

    $a=$mysqli->multi_query($sqls);
    if(!$a){
    echo "执行失败";
    }else{
    echo "成功";
    }
    $mysqli->close();

    批量执行DML语句可以混合使用delete insert update 语句,最好不要使用select语句。


    批量执行dql语句
    它可以一次性的取回多个结果集

    //打开mysqli对象
    $mysqli=new mysqli("localhost","root","","test");
    //批量查询
    $sqls="select * from emp;";
    $sqls.="select*from user1;";
    //处理结果
    if($res=$mysqli->multi_query($sqls)){
    do{
    //从mysqli连接取出第一个结果集
    $result=$mysqli->store_result();
    //显示mysqli result对象
    while($row=$result->fetch_row()){
    foreach($row as $key => $val){
    echo"--$val";
    }
    echo"
    ";
    }
    $result->free();
    echo"
    新的结果集
    ";
    }while($mysqli->next_result());
    }


  • 相关阅读:
    1523. K-inversions URAL 求k逆序对,,,,DP加树状数组
    Football 概率DP poj3071
    Collecting Bugs poj2096 概率DP
    E. Exposition
    Subsequence
    D. How many trees? DP
    hdu 1542 线段树 求矩形并
    Huge Mission
    2013 ACM/ICPC Asia Regional Chengdu Online hdu4731 Minimum palindrome
    008 jackson的一些使用记录
  • 原文地址:https://www.cnblogs.com/suiyuewuxin/p/5608513.html
Copyright © 2011-2022 走看看