如何通过pdo从mysql获取整数错误码?
try{ ... } catch(PDOException $e){ throw new Fatal($e->getMessage(), $e->getCode()); } ``` `$e->getCode()` 将返回类似 `HY000` 传递给致命参数::\uu construct()的参数2必须是integer类型,字符串给定。。。 ... 致命->构造('sqlstate[hy000]…','hy000')
ev7lccsx1#
看一看 $e->errorInfo .http://php.net/manual/en/class.pdoexception.php 说:错误信息对应于pdo::errorinfo()或pdostatement::errorinfo()http://php.net/manual/en/pdostatement.errorinfo.php 记录返回的字段 errorInfo() .例子:
$e->errorInfo
errorInfo()
try { $stmt = $pdo->query("Bogus Query"); } catch (PDOException $e) { echo "Caught exception!\n"; var_dump($e->errorInfo); }
输出:
Caught exception! array(3) { [0]=> string(5) "42000" [1]=> int(1064) [2]=> string(157) "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Bogus Query' at line 1" }
你可以看到 [1] 元素是整数。
[1]
1条答案
按热度按时间ev7lccsx1#
看一看
$e->errorInfo
.http://php.net/manual/en/class.pdoexception.php 说:
错误信息
对应于pdo::errorinfo()或pdostatement::errorinfo()
http://php.net/manual/en/pdostatement.errorinfo.php 记录返回的字段
errorInfo()
.例子:
输出:
你可以看到
[1]
元素是整数。