zoukankan      html  css  js  c++  java
  • MySqli 执行多条SQL语句

    使用multi_query();  去执行SQL语句,执行多条语句多个SQL语句用“;”分开

    一:没有结果集的语句:

    $sql="insert into products (cid,name,price,num) values('2','PHP','2.22','10');update products set cid='10',name='tong',price='33.33',num='20' where id > 10; delete from products where id< 4";
    $mysqli->multi_query($sql);

    二:有结果集的语句: 

        $sqls.="select current_user();";
        $sqls.="desc products;";
        $sqls.="select * from products;";
        $sqls.="select current_date()";
        echo "------执行有结果集的-----------------------><br>";
        if($mysqli->multi_query($sqls)){
            do{
                $result=$mysqli->store_result();        //获取结果集
                echo "<table border='1' width='600'>";
                echo "<tr>";
                while($filds=$result->fetch_field()){
                    echo "<th>{$filds->name}</th>";
                }
                echo "</tr>";
                while($row=$result->fetch_row()){
                    echo "<tr>";
                    foreach($row as $col){
                        echo "<td>{$col}</td>";
                    }
                    echo "</tr>";
                }
                echo "</table>";
                if($mysqli->more_results()){
                    echo "<br></br>";
                }
            }while($mysqli->next_result());    }
        

     

  • 相关阅读:
    ActionMQ
    解决Session共享
    Linux中使用keepalived高可用工具解决宕机问题
    Linux安装Nginx
    Nginx基础
    多线程(1)
    单例模式1(3)
    创建型模式5种(2)
    7原则(1)
    反射使用案例(2)
  • 原文地址:https://www.cnblogs.com/subtract/p/3843810.html
Copyright © 2011-2022 走看看