Home > Backend Development > PHP Tutorial > PHP的PDO以次这个程序为什么会出错

PHP的PDO以次这个程序为什么会出错

WBOY
Release: 2016-06-13 12:37:43
Original
922 people have browsed it

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 />
Copy after login


mysql:


结果是:插入出错!

不知道为什么会插入不成功??而且在数据库里真的插入不成功

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template