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

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

WBOY
Release: 2016-06-23 14:22:02
Original
829 people have browsed it

<?phptry {	$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();}
Copy after login


mysql:


结果是:插入出错!

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


回复讨论(解决方案)

$arr = $stmt->errorInfo();
print_r($arr);  //贴出结果

我懂了。。原来我的数据库字段其中两个没有填上去的不为空。。。

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