$stmt->fetchColumn
![](https://img.haomeiwen.com/i2953340/13ceb08d6ac8a46b.png)
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();
}
?>
![](https://img.haomeiwen.com/i2953340/df16705ebd6eae67.png)
Paste_Image.png
![](https://img.haomeiwen.com/i2953340/151f46f785d89d5c.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();
}
?>
![](https://img.haomeiwen.com/i2953340/45d58bef8b04cbcc.png)
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();
}
?>
![](https://img.haomeiwen.com/i2953340/32952356544ce355.png)
Paste_Image.png
网友评论