例子:
<?php //构造PDO连接 $dbh = "mysql:host=localhost;dbname=test"; $db = new PDO($dbh, 'root', 'root123'); $db->query("set character set 'gbk'"); //写入数据 $password = md5("123456"); $regdate = time(); $sql = "INSERT INTO user (username,password,email,regdate)VALUES('小陈','$password','chen@163.com', $regdate)"; $count = $db->exec($sql); echo '写入 ',$count,' 条数据记录!'; $db = null; ?>
执行该例子,浏览器输出:
写入 1 条数据记录!