} } }

    PHP mysqli扩大库 预处理惩罚技巧

    添加时间:2013-5-3 点击量:

    1、应用mysqli扩大库 预处理惩罚技巧 mysqli stmt 向数据库添加3个用户



    <?php
    

    //mysqli扩大库 预处理惩罚技巧 mysqli stmt 向数据库添加3个用户
    //1、创建mysqli对象
    ¥mysqli = new MySQLi(localhostrootroottest);
    if(¥mysqli->connect_error){
    die(¥mysqli
    ->conncet_error);
    }
    //2、创建预编译对象
    ¥sql= into user1(name,password,email,age) values(?,?,?,?);
    ¥mysqli_stmt
    =¥mysqli->prepare(¥sql);

    //绑定参数
    ¥name=小芳;
      //¥password=md5(ffff);
    ¥password
    =123456;
    ¥email
    =xiaofang@126.com;
    ¥age
    =18;

    //参数绑定->给?号赋值 这里类型温柔序要一致
    ¥mysqli_stmt->bind_param(sssi,¥name,¥password,¥email,¥age);

    //履行
    ¥b=¥mysqli_stmt->execute();

    //持续添加

    ¥name
    =小杨;
    ¥password
    =123456;
    ¥email
    =xiaoyang@126.com;
    ¥age
    =18;

    //参数绑定->给?号赋值 这里类型温柔序要一致
    ¥mysqli_stmt->bind_param(sssi,¥name,¥password,¥email,¥age);

    //履行
    ¥b=¥mysqli_stmt->execute();

    //持续添加

    ¥name
    =小G;
    ¥password
    =123456;
    ¥email
    =xiaoG@126.com;
    ¥age
    =18;

    //参数绑定->给?号赋值 这里类型温柔序要一致
    ¥mysqli_stmt->bind_param(sssi,¥name,¥password,¥email,¥age);

    //履行
    ¥b=¥mysqli_stmt->execute();

    if(!¥b){
    echo
    操纵失败.¥mysqli_stmt->error;
    }
    else{
    echo
    操纵成功;
    }
    //封闭预编译
    ¥mysqli_stmt->close();
    ¥mysqli
    ->close();
    ?>


    2、应用预处理惩罚查询id>5的用户id name email



    <?php
    

    //应用预处理惩罚查询id>5的用户id name email
    ¥mysqli=new MySQLi(localhost,root,root,test);
    if¥mysqli->connect_error){
    die¥mysqli->connect_error);
    }

    //创建预编译对象
    ¥sql= id,name,email user1 where id>?;
    ¥mysqli_stmt=¥mysqli->prepare(¥sql);

    ¥id=5;
    //绑定参数
    ¥mysqli_stmt->bind_param(i,¥id);
    //绑定成果集
    ¥mysqli_stmt->bind_result(¥id¥name¥email);
    //履行
    ¥mysqli_stmt->execute();

    //取出绑定的值
    while¥mysqli_stmt->fetch()){
    echo <br/>¥id--¥name--¥email;
    }

    //封闭资料
    //开释成果

    ¥mysqli_stmt->free_result();
    //封闭与编译语句
    ¥mysqli_stmt->close();
    //封闭连接
    ¥mysqli->close();

    ?>



    容易发怒的意思就是: 别人做了蠢事, 然后我们代替他们, 表现出笨蛋的样子。—— 蔡康永
    分享到: