Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 13231

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!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.enableexceptions.html">SQLite3::enableExceptions</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 &gt;= 5.3.0, PHP 7)</p><p class="refpurpose"><span class="refname">SQLite3::createFunction</span> &mdash; <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>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</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>
<code class="parameter">name</code></dt>

     <dd>

      <p class="para">
       Name of the SQL function to be created or redefined.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">callback</code></dt>

     <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>
      <p class="para">
       This function need to be defined as:
       <div class="methodsynopsis dc-description">
        <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><span class="replaceable">callback</span></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">$value1</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">$...</code></span>
       ] )</div>

       <dl>

        
         <dt>
<code class="parameter">value1</code></dt>

         <dd>

          <p class="para">
           The first argument passed to the SQL function.
          </p>
         </dd>

        
        
         <dt>
<code class="parameter">...</code></dt>

         <dd>

          <p class="para">
           Further arguments passed to the SQL function.
          </p>
         </dd>

        
       </dl>

      </p> 
     </dd>

    
    
     <dt>
<code class="parameter">argument_count</code></dt>

     <dd>

      <p class="para">
       The number of arguments that the SQL function takes. If
       this parameter is <em>-1</em>, then the SQL function may take
       any number of arguments.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       A bitwise conjunction of flags. Currently, only
       <strong><code>SQLITE3_DETERMINISTIC</code></strong> is supported, which specifies
       that the function always returns the same result given the same inputs
       within a single SQL statement.
      </p>
     </dd>

    
   </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 changelog" id="refsect1-sqlite3.createfunction-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.1.4</td>
      <td>
       The <code class="parameter">flags</code> parameter has been added.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3.createfunction-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2639">
    <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">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">my_udf_md5</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</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">-&gt;</span><span style="color: #0000BB">createFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'my_udf_md5'</span><span style="color: #007700">,&nbsp;</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">-&gt;</span><span style="color: #0000BB">querySingle</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT&nbsp;my_udf_md5("test")'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</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) &quot;098f6bcd4621d373cade4e832627b4f6&quot;
</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.enableexceptions.html">SQLite3::enableExceptions</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>