日期:2014-05-17 浏览次数:20512 次
<?php
try {
$dbh = new PDO('mysql:dbname=mytest;host=localhost', 'root', '19aeacv44899d4ff');
$query = 'INSERT INTO contactInfo(name, address, phone) VALUES(?, ?, ?)';
$stmt = $dbh->prepare($query);
$name = '张某某';
$address = '海珠区';
$phone = '15814535527';
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $address);
$stmt->bindParam(3, $phone);
$stmt->execute();
if ($insertID = $dbh->lastInsertId()) {
echo $insertID.'<br />';
} else {
echo '插入出错!';
exit();
}
} catch(PDOException $d) {
echo '数据库连接失败:'.$e->getMessage();
exit();
}