Source of: /manual/en/function.sqlite-exec.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sqlite.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.sqlite-exec.php',
1 => 'sqlite_exec',
),
'up' =>
array (
0 => 'ref.sqlite.php',
1 => 'SQLite Functions',
),
'prev' =>
array (
0 => 'function.sqlite-escape-string.php',
1 => 'sqlite_escape_string',
),
'next' =>
array (
0 => 'function.sqlite-factory.php',
1 => 'sqlite_factory',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.sqlite-exec" class="refentry">
<div class="refnamediv">
<h1 class="refname">sqlite_exec</h1>
<h1 class="refname">SQLiteDatabase->exec</h1>
<p class="verinfo">(PHP 5, PECL sqlite >= 1.0.3)</p><p class="refpurpose"><span class="refname">sqlite_exec</span> -- <span class="refname">SQLiteDatabase->exec</span> — <span class="dc-title">Executes a result-less query against a given database</span></p>
</div>
<a name="function.sqlite-exec.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>sqlite_exec</b></span>
( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$dbhandle</tt></span>
, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span>
[, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&$error_msg</tt></span>
] )</div>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>sqlite_exec</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span>
, <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$dbhandle</tt></span>
)</div>
<p class="para rdfs-comment">Object oriented style (method):</p>
<div class="classsynopsis">
<div class="ooclass"><b class="classname">SQLiteDatabase</b></div>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>queryExec</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span>
[, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&$error_msg</tt></span>
] )</div>
</div>
<p class="para">
Executes an SQL statement given by the <i><tt class="parameter">query</tt></i>
against
a given database handle (specified by the <i><tt class="parameter">dbhandle</tt></i>
parameter).
</p>
<div class="warning"><b class="warning">Warning</b>
<p class="simpara">
SQLite <em class="emphasis">will</em> execute multiple queries separated by
semicolons, so you can use it to execute a batch of SQL that you have
loaded from a file or have embedded in a script.
</p>
</div>
</div>
<a name="function.sqlite-exec.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">dbhandle</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The SQLite Database resource; returned from
<a href="function.sqlite-open.php" class="function">sqlite_open()</a> when used procedurally. This parameter
is not required when using the object-oriented method.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">query</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The query to be executed.
</p>
<p class="para">
Data inside the query should be <a href="function.sqlite-escape-string.php" class="link">properly escaped</a>.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">error_msg</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The specified variable will be filled if an error occurs. This is
specially important because SQL syntax errors can't be fetched using
the <a href="function.sqlite-last-error.php" class="function">sqlite_last_error()</a> function.
</p>
</dd>
</dl>
<p>
</p>
<blockquote><p><b class="note">Note</b>: <span class="simpara">Two alternative syntaxes are
supported for compatibility with other database extensions (such as MySQL).
The preferred form is the first, where the <i><tt class="parameter">dbhandle</tt></i>
parameter is the first parameter to the function.</span></p></blockquote>
</div>
<a name="function.sqlite-exec.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
This function will return a boolean result; <b><tt class="constant">TRUE</tt></b> for success or <b><tt class="constant">FALSE</tt></b> for failure.
If you need to run a query that returns rows, see <a href="function.sqlite-query.php" class="function">sqlite_query()</a>.
</p>
<p class="para">The column names returned by
<b><tt class="constant">SQLITE_ASSOC</tt></b> and <b><tt class="constant">SQLITE_BOTH</tt></b> will be
case-folded according to the value of the
<a href="sqlite.configuration.php#ini.sqlite.assoc-case" class="link">sqlite.assoc_case</a> configuration
option.</p>
</div>
<a name="function.sqlite-exec.changelog"></a><div class="refsect1 changelog">
<h3 class="title">Changelog</h3>
<p class="para">
</p><table class="doctable informaltable">
<thead valign="middle">
<tr valign="middle">
<th>Version</th>
<th>Description</th>
</tr>
</thead>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left">5.1.0</td>
<td align="left">
Added the <i><tt class="parameter">error_msg</tt></i>
parameter
</td>
</tr>
</tbody>
</table>
<p>
</p>
</div>
<a name="function.sqlite-exec.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 Procedural example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br />$dbhandle </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">, </span><span style="color: #DD0000">"UPDATE users SET email='jDoe@example.com' WHERE username='jDoe'"</span><span style="color: #007700">, </span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$query</span><span style="color: #007700">) {<br /> exit(</span><span style="color: #DD0000">"Error in query: '</span><span style="color: #0000BB">$error</span><span style="color: #DD0000">'"</span><span style="color: #007700">);<br />} else {<br /> echo </span><span style="color: #DD0000">'Number of rows modified: '</span><span style="color: #007700">, </span><span style="color: #0000BB">sqlite_changes</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
<p class="para">
</p><div class="example">
<p><b>Example #2 Object-oriented example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br />$dbhandle </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLiteDatabase</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-></span><span style="color: #0000BB">queryExec</span><span style="color: #007700">(</span><span style="color: #DD0000">"UPDATE users SET email='jDoe@example.com' WHERE username='jDoe'"</span><span style="color: #007700">, </span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$query</span><span style="color: #007700">) {<br /> exit(</span><span style="color: #DD0000">"Error in query: '</span><span style="color: #0000BB">$error</span><span style="color: #DD0000">'"</span><span style="color: #007700">);<br />} else {<br /> echo </span><span style="color: #DD0000">'Number of rows modified: '</span><span style="color: #007700">, </span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-></span><span style="color: #0000BB">changes</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div>
<a name="function.sqlite-exec.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.sqlite-query.php" class="function" rel="rdfs-seeAlso">sqlite_query()</a> - Executes a query against a given database and returns a result handle</li>
<li class="member"><a href="function.sqlite-unbuffered-query.php" class="function" rel="rdfs-seeAlso">sqlite_unbuffered_query()</a> - Execute a query that does not prefetch and buffer all data</li>
<li class="member"><a href="function.sqlite-array-query.php" class="function" rel="rdfs-seeAlso">sqlite_array_query()</a> - Execute a query against a given database and returns an array</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>