<!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>Registers a PHP function for use as an SQL scalar function</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3.createcollation.html">SQLite3::createCollation</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.createfunction" class="refentry"> <div class="refnamediv"> <h1 class="refname">SQLite3::createFunction</h1> <p class="verinfo">(PHP 5 >= 5.3.0)</p><p class="refpurpose"><span class="refname">SQLite3::createFunction</span> — <span class="dc-title">Registers a PHP function for use as an SQL scalar function</span></p> </div> <div class="refsect1 description" id="refsect1-sqlite3.createfunction-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>SQLite3::createFunction</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$callback</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$argument_count</code><span class="initializer"> = -1</span></span> ] )</div> <p class="para rdfs-comment"> Registers a PHP function or user-defined function for use as an SQL scalar function for use within SQL statements. </p> </div> <div class="refsect1 parameters" id="refsect1-sqlite3.createfunction-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">name</code></em></span> <dd> <p class="para"> Name of the SQL function to be created or redefined. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">callback</code></em></span> <dd> <p class="para"> The name of a PHP function or user-defined function to apply as a callback, defining the behavior of the SQL function. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">argument_count</code></em></span> <dd> <p class="para"> The number of arguments that the SQL function takes. If this parameter is negative, then the SQL function may take any number of arguments. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-sqlite3.createfunction-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> upon successful creation of the function, <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-sqlite3.createfunction-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2158"> <p><strong>Example #1 <span class="function"><strong>SQLite3::createFunction()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">my_udf_md5</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">) {<br /> return </span><span style="color: #0000BB">md5</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb.db'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">createFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'my_udf_md5'</span><span style="color: #007700">, </span><span style="color: #DD0000">'my_udf_md5'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">querySingle</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT my_udf_md5("test")'</span><span style="color: #007700">));<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> string(32) "098f6bcd4621d373cade4e832627b4f6" </pre></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3.createcollation.html">SQLite3::createCollation</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>