zoukankan      html  css  js  c++  java
  • php中bindValue 和 bindParam 的区别

    // 注意:
    // bindParam是绑定一个PHP变量到一个SQL参数.是引用方式传递
    // 所以你可以改变变量值,再执行.就赋给SQL语句不同的值
    // 注意与bindValue的区别

    try {   
    $sql = 'UPDATE `pdo` set `user` = :user, `email` = :email WHERE `id` = :id';
    $pre = $dbh->prepare($sql);   
    // 此处bindParam.执行一次更改id=2,执行一次更改id=3.结果不一样
    $user = "ncat2";
    $email = "ncat2@gmail.com";
    $id = 2;
    $pre->bindParam(':user', $user, PDO::PARAM_STR);
    $pre->bindParam(':email', $email, PDO::PARAM_STR);
    $pre->bindParam(':id', $id, PDO::PARAM_INT);
    $pre->execute();$user = "ncat3";
    $email = "ncat3@gmail.com";
    $id = 3;
    $pre->execute();
    unset($user, $email, $id);
    // 此处bindValue. 执行两次id=4的SQL$user = "ncat4";
    $email = "ncat4@gmail.com";
    $id = 4;
    $pre->bindValue(':user', $user, PDO::PARAM_STR);
    $pre->bindValue(':email', $email, PDO::PARAM_STR);
    $pre->bindValue(':id', $id, PDO::PARAM_INT);
    $pre->execute();
    $user = "ncat5";
    $email = "ncat5@gmail.com";
    $id = 5;$pre->execute();
    } catch (PDOException $e)
    {var_dump($e);}

  • 相关阅读:
    UVa 107 The Cat in the Hat
    UVa 591 Box of Bricks
    UVa 253 Cube painting
    UVa 10161 Ant on a Chessboard
    UVa 401 Palindromes
    UVa 465 Overflow
    我不知道
    消防局的设立
    某CF的D
    保安站岗
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/1716963.html
Copyright © 2011-2022 走看看