Blogger Information
Blog 65
fans 3
comment 4
visits 67607
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
mysqli之多天SQL命令同时操作 0415/11:17
无耻的鱼
Original
840 people have browsed it

其实呢,SQL语句的多条与单挑执行都是一样的,只是执行语句有所差别

  • 单条的执行语句是:mysqlI_query()

  • 多条一起执行的是:mysqli_multi_query_()

下面咱们来看看代码

先看看单条语句操作


实例

<?php
/**
 * User: Z先生
 * Date: 2018/4/24
 */
require 'connect.php';

$sql = "DELETE  FROM aaa WHERE name='二青'";


if(mysqli_query($db,$sql)){
    if(mysqli_affected_rows($db) > 0){
    echo '删除数目为:'.mysqli_affected_rows($db);
    }else{
        echo '没有删除';
    }
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

这是一个简单的删除命令操作

下面在看看多条操作,然后呢再对比一下

实例

<?php
/**
 * User: Z先生
 * Date: 2018/4/25
 */
require 'connect.php';

//多条语句
$sql = "INSERT IGNORE aaa SET name='柳7',age=23,money=8000;";
$sql .="UPDATE aaa SET money=8900 WHERE id=24;";
$sql .="DELETE FROM aaa WHERE id=10 ";

//多条语句执行
//mysqli_multi_query()
if(mysqli_multi_query($db,$sql)){
    if(mysqli_affected_rows($db)>0){

        if(mysqli_insert_id($db)>0){
                    echo '第'.mysqli_affected_rows($db).'条记录,ID是:'.mysqli_insert_id($db);
        }
        echo '数据更新了:'.mysqli_affected_rows($db);
    }
    else{
        echo '没有数据被更新';
    }
}

//echo mysqli_errno($db),mysqli_error($db);

mysqli_close($db);

//结果总结?1当第一条数据无效时,mysqli_nulti_query()执行没有返回的mysqli_affected_rows()

运行实例 »

点击 "运行实例" 按钮查看在线实例

那么通过对比是不是就可以看出来呢?


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post