SQLite3::enableExceptions
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
SQLite3::enableExceptions — 예외 처리 활성화
설명
public SQLite3::enableExceptions(bool $enable
= false
): bool
SQLite3 인스턴스가 오류 시 예외 또는 경고를 발생시킬지 여부를 제어합니다.
매개변수
enable
true
인 경우 SQLite3 인스턴스와 이 인스턴스에서 파생된 SQLite3Stmt 및 SQLite3Result 인스턴스는 오류 시 예외를 throw합니다.false
인 경우 SQLite3 인스턴스와 이 인스턴스에서 파생된 SQLite3Stmt 및 SQLite3Result 인스턴스는 오류 시 경고를 발생시킵니다.두 모드 모두에서 오류 코드와 메시지(있는 경우)는 각각 SQLite3::lastErrorCode() 및 SQLite3::lastErrorMsg()를 통해 사용할 수 있습니다.
반환 값
이전 값을 반환합니다. 예외가 활성화되면 true
, 그렇지 않으면 false
입니다.
Examples
예제 #1 SQLite3::enableExceptions() 예제
<?php
$sqlite = new SQLite3(':memory:');
try {
$sqlite->exec('create table foo');
$sqlite->enableExceptions(true);
$sqlite->exec('create table bar');
} catch (Exception $e) {
echo 'Caught exception: ' . $e->getMessage();
}
?>
위의 예는 다음과 유사한 결과를 출력합니다.
Warning: SQLite3::exec(): near "foo": syntax error in example.php on line 4 Caught exception: near "bar": syntax error