首页 > 技术文章 > pdo 函数

hiraeth 2018-04-02 17:56 原文

$conn = new \PDO;

$stmt=$conn->prepare($sql); 预处理语句重复插入 占位符

<?php
$stmt $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name'$name);
$stmt->bindParam(':value'$value);

// 插入一行
$name 'one';
$value 1;
$stmt->execute();

//  用不同的值插入另一行
$name 'two';
$value 2;
$stmt->execute();
?>

推荐阅读