PDO添加数据的预处理语句

1.添加页面
<h1>添加数据</h1>

<form action="chuli.php" method="post">
<div>代号:<input type="text" name="code" /></div>
<div>名称:<input type="text" name="name" /></div>
<input type="submit" value="添加" />
</form>





2.处理页面
(1)造PDO对象

$dsn = "mysql:dbname=mydb;host=localhost";
$pdo = new PDO($dsn,"root","123");

(2)预处理语句
$sql = "insert into nation values(:code,:name)";
$stm = $pdo->prepare($sql);

(3)执行
$stm->execute($_POST);



posted @ 2017-03-02 15:32  周全264  阅读(1101)  评论(0编辑  收藏  举报