因为在使用uchome的老框架,开发中发现对于重复插入主键数据时mysql报错,但是try catch获取不到异常(特意测试使用try catch抛异常没问题),我想知道如何可以获取到这种数据库错误的异常,跪求解决办法!!!!!!
MySQLPHP异常

解决方案 »

  1.   

    用mysqli吧:$driver = new mysqli_driver();
    $driver->report_mode = MYSQLI_REPORT_STRICT;try {
        $result = $mysqli->query("");
        $result->close();
        $mysqli->close();
    } catch (mysqli_sql_exception $e) {
        //
    }
      

  2.   

    mysql_errno
    (PHP 3, PHP 4, PHP 5)mysql_errno -- Returns the numerical value of the error message from previous MySQL operation
    Description
    int mysql_errno ( [resource link_identifier] )
    Returns the error number from the last MySQL function. Errors coming back from the MySQL database backend no longer issue warnings. Instead, use mysql_errno() to retrieve the error code. Note that this function only returns the error code from the most recently executed MySQL function (not including mysql_error() and mysql_errno()), so if you want to use it, make sure you check the value before calling another MySQL function. 
      

  3.   

    主键重复,php会提示出来的,不需要人为去控制。