我想从这个错误中得到确切的消息

时间:2011-03-07 05:11:32

标签: php mysql exception-handling

我知道我必须在某处包含mysql_errno和mysql_error,而不是'查询失败',我尝试将$ results作为参数,但我还没有找到。

如果有人可以帮助我,谢谢:

static function execSQl2($query)
{
/*
        Execute a SQL query on the database
        passing the tablename and the sql query.
        Returns the LAST_INSERT_ID
*/

    $db = null;
    $lastid = null;
    //echo "query is $query";

    try
    {
        $db = Model::getConnection();
        $results = $db->query($query);
        if(!$results) {
            throw new Exception('Query failed', EX_QUERY_FAILED);
        }
        $lastid = $db->insert_id;
    }
    catch(Exception $e)
    {
        /*  errors are handled higher in the
                object hierarchy
        */

        throw $e;
    }

    Model::closeConnection($db);
    return $lastid;
}

1 个答案:

答案 0 :(得分:4)

 throw new Exception(mysql_error(), EX_QUERY_FAILED);