• 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());    }
        

     

  • 相关阅读:
    用VisualSVN做项目版本控制
    jQuery 停止动画
    jQuery 效果
    jQuery 效果
    jQuery 效果
    jQuery 事件
    jQuery 选择器
    jQuery 语法(一)
    Form.ShowWithoutActivation 属性
    C#里面中将字符串转为变量名
  • 原文地址:https://www.cnblogs.com/subtract/p/3843810.html
Copyright © 2020-2023  润新知