$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
网友评论