美文网首页
[PDO]①③--debugDumpParams

[PDO]①③--debugDumpParams

作者: 子木同 | 来源:发表于2017-09-04 16:36 被阅读24次

    $stmt->fetchColumn

    Paste_Image.png
    <?php
    header('content-type:text/html;charset=utf-8');
    try {
        $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
        $sql = "SELECT username,password,email FROM user";
        $stmt = $pdo->query($sql);
        echo $stmt->fetchColumn(0), "<br/>";
        echo $stmt->fetchColumn(1), "<br/>";
        echo $stmt->fetchColumn(2), "<br/>";
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    ?>
    
    Paste_Image.png Paste_Image.png

    $stmt->debugDumpParams()

    <?php
    try {
        $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
        $sql = "INSERT user(username,password,email) VALUES(?,?,?)";
        $stmt = $pdo->prepare($sql);
        $stmt->bindParam(1, $username, PDO::PARAM_STR);
        $stmt->bindParam(2, $password, PDO::PARAM_STR);
        $stmt->bindParam(3, $email, PDO::PARAM_STR);
        $username = 'testParam';
        $password = 'testParam';
        $email = 'testparam@imooc.com';
        $stmt->execute();
        $stmt->debugDumpParams();
    
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    ?>
    
    Paste_Image.png
    <?php
    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->bindParam(':username', $username, PDO::PARAM_STR);
        $stmt->bindParam(':password', $password, PDO::PARAM_STR);
        $username = 'testParam3';
        $password = 'testParam4';
        $email = 'testParam@imooc.com';
        $stmt->execute();
        $stmt->debugDumpParams();
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    ?>
    
    Paste_Image.png

    相关文章

      网友评论

          本文标题:[PDO]①③--debugDumpParams

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