PHP 8.5.10 Released!

SQLite3::enableExtendedResultCodes

(PHP 7 >= 7.4.0, PHP 8)

SQLite3::enableExtendedResultCodes Enables or disables the use of extended result codes

説明

public function SQLite3::enableExtendedResultCodes(bool $enable = true): bool

Enables or disables the use of extended result codes, which are then reported by SQLite3::lastErrorCode(). SQLite3::lastExtendedErrorCode() is not affected by this setting, and always returns the extended result code.

パラメータ

enable

Whether to enable (true) or disable (false) the use of extended result codes.

戻り値

成功した場合に true を、失敗した場合に false を返します。

例1 SQLite3::enableExtendedResultCodes() example

<?php
$db = new SQLite3(':memory:');
$db->enableExceptions(true);
$db->exec('CREATE TABLE t (a INTEGER UNIQUE)');
$db->exec('INSERT INTO t VALUES (1)');

try {
    $db->exec('INSERT INTO t VALUES (1)');
} catch (Exception $e) {
}

// The primary result code (SQLITE_CONSTRAINT), then the extended result
// code (SQLITE_CONSTRAINT_UNIQUE).
var_dump($db->lastErrorCode(), $db->lastExtendedErrorCode());

// Once enabled, SQLite3::lastErrorCode() reports the extended result code
// as well.
$db->enableExtendedResultCodes();
var_dump($db->lastErrorCode());
?>

上の例の出力は以下となります。

int(19)
int(2067)
int(2067)

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top