PDOException 的输出 怎么不一致呢?PDOException继承自exception,拥有父类的所有方法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?phptry{ # PDO Blah blah blah……}catch (PDOException $e){ throw new Exception($e->getMessage(),$e->getCode());}?>转换一下就好. SysTem128的方法可以解决输出格式统一的问题,但是在catch一个异常的时候再去抛出一个异常是不是有点不符合规范。请问有没有更好的解决办法呢? 如果继承PDOException或Exception的话还是得将不同的异常抛出到这个子Exception对象里.捕获的时候抛出是一个小窍门,很实用,没有什么不规范的. PDOException 不正常工作:我的数据库是mysql5.0.41, WinXp平台的,为什么PDO::exec就不抛出错误呢?还有问题就是:PDOException应该如何初始化?如题的方式不工作~~例如:try {....... $isOk = $pdh->exec($insPicCridSql); if (!$isOk) {print "rollback1;\n"; $pdh->rollBack(); $err=$pdh->errorInfo(); print "$err[2],$err[1]\n"; throw new PDOException($err[2],$err[1]); } $pdh->commit(); }catch (PDOException $e) { $this->errId = _PICTURE_DB_ERROR; $this->errStr = "Database error in commitCrid error($e->getCode():$e->getMessage())";print ($this->errStr.'\n'); ....... }输出的结果如下:rollback1;Duplicate entry '200000000031200000100311780007900011670206802000-1 (1).jpg' for key 2,1062Database error in commitCrid error(():())。 PHP网站上线之数据库问题?求帮助 搞前端的,请教一个简单php问题 php怎么实现QQ自动登录? 图片名字乱码 一个简单得不能在简单的“大问题” 在线等,这个正则表达式应该如何写? 组建团队,有什么好的建议? 关于PHP使用LDAP的问题! 还是session的问题,高分相赠,在线等待。 一个php的问题? 关于传递的参数写入数据库 跪请
try{
# PDO Blah blah blah……
}
catch (PDOException $e){
throw new Exception($e->getMessage(),$e->getCode());
}
?>转换一下就好.
捕获的时候抛出是一个小窍门,很实用,没有什么不规范的.
还有问题就是:PDOException应该如何初始化?如题的方式不工作~~
例如:
try {
.......
$isOk = $pdh->exec($insPicCridSql);
if (!$isOk) {
print "rollback1;\n";
$pdh->rollBack();
$err=$pdh->errorInfo();
print "$err[2],$err[1]\n";
throw new PDOException($err[2],$err[1]);
}
$pdh->commit();
}catch (PDOException $e) {
$this->errId = _PICTURE_DB_ERROR;
$this->errStr = "Database error in commitCrid error($e->getCode():$e->getMessage())";
print ($this->errStr.'\n');
.......
}
输出的结果如下:
rollback1;Duplicate entry '200000000031200000100311780007900011670206802000-1 (1).jpg' for key 2,1062
Database error in commitCrid error(():())。