Maison >développement back-end >tutoriel php > PHP的PDO以次这个程序为什么会出错
PHP的PDO以下这个程序为什么会出错?
<br /> <?php<br /> try {<br /> $dbh = new PDO('mysql:dbname=mytest;host=localhost', 'root', '19aeacv44899d4ff');<br /> <br /> $query = 'INSERT INTO contactInfo(name, address, phone) VALUES(?, ?, ?)';<br /> $stmt = $dbh->prepare($query);<br /> <br /> $name = '张某某';<br /> $address = '海珠区';<br /> $phone = '15814535527';<br /> $stmt->bindParam(1, $name);<br /> $stmt->bindParam(2, $address);<br /> $stmt->bindParam(3, $phone);<br /> <br /> $stmt->execute();<br /> if ($insertID = $dbh->lastInsertId()) {<br /> echo $insertID.'<br />';<br /> } else {<br /> echo '插入出错!';<br /> exit();<br /> }<br /> } catch(PDOException $d) {<br /> echo '数据库连接失败:'.$e->getMessage();<br /> exit();<br /> }<br /> <br />