[PDO]①②--绑定参数

$stmt->bindParam

prepare($sql);
    $stmt->bindParam(":username", $username, PDO::PARAM_STR);
    $stmt->bindParam(":password", $password, PDO::PARAM_STR);
    $stmt->bindParam(":email", $email);
    $username = 'imooc1';
    $password = 'imooc1';
    $email = '[email protected]';
    $stmt->execute();
    $username = 'mrking1';
    $password = "mrking1";
    $stmt->execute();//1
    echo $stmt->rowCount();
} catch (PDOException $e) {
    echo $e->getMessage();
}

?>

$stmt->bindValue

?

prepare($sql);
    $username = 'imooc_king3';
    $password = 'imooc_king3';
    $stmt->bindValue(1, $username);
    $stmt->bindValue(2, $password);
    $stmt->bindValue(3, '[email protected]');
    $stmt->execute();
    echo $stmt->rowCount()."
";//1或0 $stmt->bindValue(1, "imooc_king2"); $stmt->bindValue(2, "imooc_king2"); $stmt->bindValue(3, '[email protected]'); $stmt->execute(); echo $stmt->rowCount();//1或0 } catch (PDOException $e) { echo $e->getMessage(); }

:username

prepare($sql);
    $username = "imooc_king4";
    $password = "imooc_king4";
    $stmt->bindValue(':username', $username);
    $stmt->bindValue(':password', $password);
    $stmt->bindValue(':email', '[email protected]');
    $stmt->execute();
    echo $stmt->rowCount();

} catch (PDOException $e) {
    echo $e->getMessage();
}

Paste_Image.png
Paste_Image.png
Paste_Image.png

$stmt->columnCount()

$stmt->bindColumn

$stmt->fetch(PDO::FETCH_BOUND)

prepare($sql);
    $stmt->execute();
    echo "结果集中的列数一共有:" . $stmt->columnCount() . "
"; var_dump($stmt->getColumnMeta(0)); $stmt->bindColumn(1, $username); $stmt->bindColumn(2, $password); $stmt->bindColumn(3, $email); while ($stmt->fetch(PDO::FETCH_BOUND)) { echo '用户名:' . $username . '密码:' . $password . '-邮箱:' . $email . '
'; } } catch (PDOException $e) { echo $e->getMessage(); } ?>
[PDO]①②--绑定参数_第1张图片
Paste_Image.png

你可能感兴趣的:([PDO]①②--绑定参数)