【问题标题】:I want to get the exact message out of this error我想从这个错误中得到确切的信息
【发布时间】:2011-03-07 05:11:31
【问题描述】:

我知道我必须在此处包含 mysql_errno y 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;
}

【问题讨论】:

  • 看起来您正在使用某种框架。您应该查看它的文档,了解正在使用的数据库类如何报告错误。

标签: php mysql exception-handling


【解决方案1】:
 throw new Exception(mysql_error(), EX_QUERY_FAILED);

【讨论】:

    猜你喜欢
    • 2018-11-30
    • 2022-01-25
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    相关资源
    最近更新 更多