我在PHP中有以下课程

class MyDB extends SQLite3
{
    function __construct()
    {
        $this->open('Database.db');
    }
}


它由$db = new MyDB();调用。有没有办法让$db->errorInfo()返回数据库的errorInfo()函数?

最佳答案

您的课程扩展了SQLite3 class,但扩展了errorInfo() is a method of PDOSQLite3对象的等效错误报告机制是SQLite3::lastErrorMsg()的组合,用于显示消息文本和SQLite3::lastErrorCode()

假设您已经扩展了该类,则这些公共方法对于您的$db对象已经可用。

echo "SQL error: " . $db->lastErrorMsg();
echo "SQL error code: " . $db->lastErrorCode();


SQLite3PDO::errorInfo()并不完全等效,但是返回错误代码和消息的关联数组。您只需要致电lastErrorMsg()lastErrorCode()获得所需的报告。

关于php - PHP类返回ErrorInfo(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34242569/

10-12 00:23
查看更多