<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Enable throwing exceptions</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3.createfunction.html">SQLite3::createFunction</a></div> <div class="next" style="text-align: right; float: right;"><a href="sqlite3.escapestring.html">SQLite3::escapeString</a></div> <div class="up"><a href="class.sqlite3.html">SQLite3</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="sqlite3.enableexceptions" class="refentry"> <div class="refnamediv"> <h1 class="refname">SQLite3::enableExceptions</h1> <p class="verinfo">(PHP 5 >= 5.3.0, PHP 7)</p><p class="refpurpose"><span class="refname">SQLite3::enableExceptions</span> — <span class="dc-title"> Enable throwing exceptions </span></p> </div> <div class="refsect1 description" id="refsect1-sqlite3.enableexceptions-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>SQLite3::enableExceptions</strong></span> ([ <span class="methodparam"><span class="type">bool</span> <code class="parameter">$enableExceptions</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span> ] )</div> <p class="para rdfs-comment"> Controls whether the <a href="class.sqlite3.html" class="classname">SQLite3</a> instance will throw exceptions or warnings on error. </p> </div> <div class="refsect1 parameters" id="refsect1-sqlite3.enableexceptions-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">enable</code></dt> <dd> <p class="para"> When <strong><code>TRUE</code></strong>, the <a href="class.sqlite3.html" class="classname">SQLite3</a> instance, and <a href="class.sqlite3stmt.html" class="classname">SQLite3Stmt</a> and <a href="class.sqlite3result.html" class="classname">SQLite3Result</a> instances derived from it, will throw exceptions on error. </p> <p class="para"> When <strong><code>FALSE</code></strong>, the <a href="class.sqlite3.html" class="classname">SQLite3</a> instance, and <a href="class.sqlite3stmt.html" class="classname">SQLite3Stmt</a> and <a href="class.sqlite3result.html" class="classname">SQLite3Result</a> instances derived from it, will raise warnings on error. </p> <p class="para"> For either mode, the error code and message, if any, will be available via <span class="methodname"><a href="sqlite3.lasterrorcode.html" class="methodname">SQLite3::lastErrorCode()</a></span> and <span class="methodname"><a href="sqlite3.lasterrormsg.html" class="methodname">SQLite3::lastErrorMsg()</a></span> respectively. </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-sqlite3.enableexceptions-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the old value; <strong><code>TRUE</code></strong> if exceptions were enabled, <strong><code>FALSE</code></strong> otherwise. </p> </div> <div class="refsect1 examples" id="refsect1-sqlite3.enableexceptions-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-2640"> <p><strong>Example #1 <span class="methodname"><strong>SQLite3::enableExceptions()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$sqlite </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">':memory:'</span><span style="color: #007700">);<br />try {<br /> </span><span style="color: #0000BB">$sqlite</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'create table foo'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$sqlite</span><span style="color: #007700">-></span><span style="color: #0000BB">enableExceptions</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$sqlite</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'create table bar'</span><span style="color: #007700">);<br />} catch (</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">'Caught exception: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$e</span><span style="color: #007700">-></span><span style="color: #0000BB">getMessage</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Warning: SQLite3::exec(): near "foo": syntax error in example.php on line 4 Caught exception: near "bar": syntax error </pre></div> </div> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3.createfunction.html">SQLite3::createFunction</a></div> <div class="next" style="text-align: right; float: right;"><a href="sqlite3.escapestring.html">SQLite3::escapeString</a></div> <div class="up"><a href="class.sqlite3.html">SQLite3</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>