美文网首页
[PDO]①①--预处理语句中的占位符

[PDO]①①--预处理语句中的占位符

作者: 子木同 | 来源:发表于2017-09-04 10:51 被阅读0次
    <?php
    header('content-type:text/html;charset=utf-8');
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    try {
        $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
        $sql = "select * from user where username=:username and password=:password";
        $stmt = $pdo->prepare($sql);
        $stmt->execute(array(":username" => $username, ":password" => $password));
        echo $stmt->rowCount();
    
    //    $sql = "select * from user where username='king2' and password='king2'";
    //    $stmt = $pdo->prepare($sql);
    //    $stmt->execute(array($username, $password));
    //    echo $stmt->rowCount();
    
    
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    
    ?>
    
    Paste_Image.png

    相关文章

      网友评论

          本文标题:[PDO]①①--预处理语句中的占位符

          本文链接:https://www.haomeiwen.com/subject/hmgsjxtx.html