码迷,mamicode.com
首页 > 数据库 > 详细

MySqli 执行多条SQL语句

时间:2014-07-15 23:12:08      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   使用   strong   

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

 

 

MySqli 执行多条SQL语句,布布扣,bubuko.com

MySqli 执行多条SQL语句

标签:des   style   blog   color   使用   strong   

原文地址:http://www.cnblogs.com/subtract/p/3843810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!