首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

SQLite3::enableExceptions

(PHP 5 >= 5.3.0, PHP 7)

SQLite3::enableExceptions - 启用抛出异常

描述

代码语言:javascript
复制
bool SQLite3::enableExceptions ([ bool $enableExceptions = false ] )

控制SQLite3实例是否会在出错时抛出异常或警告。

参数

enable

TRUE时,SQLite3实例以及从它派生的SQLite3Stmt和SQLite3Result实例在错误时会抛出异常。

FALSE时,SQLite3实例以及从它派生的SQLite3Stmt和SQLite3Result实例将在出现错误时引发警告。

对于任一模式,错误代码和消息(如果有的话)将分别通过SQLite3::lastErrorCode()和SQLite3::lastErrorMsg()提供。

返回值

返回旧值;TRUE如果启用了异常,否则返回FALSE

示例

Example #1 SQLite3::enableExceptions() example

代码语言:javascript
复制
<?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();
}
?>

上面的例子会输出类似于:

代码语言:javascript
复制
Warning: SQLite3::exec(): near "foo": syntax error in example.php on line 4
Caught exception: near "bar": syntax error

← SQLite3::createFunction

SQLite3::escapeString →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com