从php中的异常获取`sqlstate`代码

时间:2016-08-02 10:27:31

标签: php mysql

我正在尝试从以下异常对象获取sqlslate代码:

SQLSTATE[42000]: Syntax error or access violation: 1064 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 xx at line 1 in xx.

我正在使用以下代码:

 var_dump("code is: ".$exception->getCode());

但它会返回0。我怎样才能获得像420000这样的代码。

0 个答案:

没有答案