$st = $this->pdo->prepare(insert into $tablename ($field) values($code));
$st->execute($arr);
if ($this->pdo->errorcode() != '00000')test($this->pdo->errorinfo());
return $this->pdo->lastinsertid();
故意让一个不能为空的字段给一个空值,然后上面的代码执行后获取不到错误(也输出过errorcode() 是= '00000'),但pdo->lastinsertid()返回的是0,打开数据库去看也是没有成功新增记录,这种pdo预处理的sql该怎么获取错误提示?
回复讨论(解决方案) if ($st->errorcode() != '00000') test($st->errorinfo());
或 $this->pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception);
后,使用异常处理
try { .... $st->execute($arr); ....} catch (pdoexception $e) { print error!: . $e->getmessage() . \n;}
