如何使用FluentPDO检测错误


How to detect errors using FluentPDO

我正在使用FluentPDO构建我的查询。

当我执行insert语句时,如果无法执行,它会返回False。但是,我不知道如何检索失败背后的错误。

有人知道在使用这个库时如何处理错误吗?

这是我当前的代码。。。

function doInsert() {
    $pdo = new PDO("mysql:dbname=blog", "root", "password");
    $fpdo = new FluentPDO($pdo);
    $values = [
        'field1' => 'value 1',
        'field2' => 'value 2',
        'field3' => 'value 3',
    ];
    $query = $fpdo->insertInto('my_table', $values)->execute();
    if (!$query) {
        // what to type here to determine error
    }
}

这不是答案,而是作者的解释(FluentPDO/BaseQuery.php Line:98):

    // At this point, $result is a PDOStatement instance, or false.
    // PDO::prepare() does not reliably return errors. Some database drivers
    // do not support prepared statements, and PHP emulates them.  Postgres
    // does support prepared statements, but PHP does not call Postgres's
    // prepare function until we call PDOStatement::execute() (below).
    // If PDO::prepare() worked properly, this is where we would check
    // for prepare errors, such as invalid SQL.