从数据库获取数据就以下这两个脚本足够

php
    $mysqli=new mysqli("localhost", "root", "123456", "xsphpdb");



    //准备好一条语句放到服务器中,插入语句
    $sql="insert into shops(name, price, num, desn) values(?, ?, ?, ?)";

    $stmt=$mysqli->prepare($sql);

    //给占位符号每个?号传值(绑定参数) i  d  s  b 
    $stmt->bind_param("sdis", $name, $price, $num, $desn);

    $name="zhangsan";
    $price=56.78;
    $num=66;
    $desn="hello good";    

    //执行
    $stmt->execute();


    $name="lisi";
    $price=56.78;
    $num=66;
    $desn="aaaaaaaa";    

    //执行
    $stmt->execute();


    $name="wangwu";
    $price=56.78;
    $num=96;
    $desn="bbbbbbbbb";    

    //执行
    $stmt->execute();


    $name="zhaoliu";
    $price=56.78;
    $num=68;
    $desn="cccccccccccc";    

    //执行
    $stmt->execute();

    echo "最后ID".$stmt->insert_id."
"; echo "影响了".$stmt->affected_rows."行
"; $stmt->close();

 

你可能感兴趣的:(从数据库获取数据就以下这两个脚本足够)