<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.sqlite3.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'es',
  ),
  'this' => 
  array (
    0 => 'sqlite3.createcollation.php',
    1 => 'SQLite3::createCollation',
    2 => 'Registra una funci&oacute;n PHP para utilizarla como funci&oacute;n de clasificaci&oacute;n SQL',
  ),
  'up' => 
  array (
    0 => 'class.sqlite3.php',
    1 => 'SQLite3',
  ),
  'prev' => 
  array (
    0 => 'sqlite3.createaggregate.php',
    1 => 'SQLite3::createAggregate',
  ),
  'next' => 
  array (
    0 => 'sqlite3.createfunction.php',
    1 => 'SQLite3::createFunction',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    'path' => 'reference/sqlite3/sqlite3/createcollation.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="sqlite3.createcollation" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SQLite3::createCollation</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.11, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SQLite3::createCollation</span> &mdash; <span class="dc-title">Registra una función PHP para utilizarla como función de clasificación SQL</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-sqlite3.createcollation-description">
  <h3 class="title">Descripción</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SQLite3::createCollation</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$name</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Registra una función PHP o una función definida por el usuario para
   utilizarla como función de clasificación en una consulta SQL.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-sqlite3.createcollation-parameters">
  <h3 class="title">Parámetros</h3>
  <dl>
   
    <dt><code class="parameter">name</code></dt>
    <dd>
     <p class="para">
      Nombre de la función de clasificación SQL a crear o redefinir.
     </p>
    </dd>
   
   
    <dt><code class="parameter">callback</code></dt>
    <dd>
     <p class="para">
      El nombre de una función PHP o de una función definida por el usuario
      a aplicar como función de retorno, definiendo el comportamiento
      de la clasificación. Debe aceptar dos argumentos y retornará
      lo mismo que la función <span class="function"><a href="function.strcmp.php" class="function">strcmp()</a></span>, es decir
      debe retornar -1, 1, o 0 si la primera cadena se clasifica antes,
      después, o es equivalente a la segunda.
     </p>
     <p class="para">
      Esta función debe ser definida como:
      <div class="methodsynopsis dc-description">
       <span class="methodname"><span class="replaceable">collation</span></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value1</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value2</code></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-sqlite3.createcollation-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Esta función retorna <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> en caso de éxito o <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si ocurre un error.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3.createcollation-examples">
  <h3 class="title">Ejemplos</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Ejemplo #1 Ejemplo con <span class="function"><strong>SQLite3::createCollation()</strong></span></strong></p>
    <div class="example-contents"><p>
     Registra la función PHP <span class="function"><a href="function.strnatcmp.php" class="function">strnatcmp()</a></span> como
     secuencia de clasificación en la base de datos SQLite3.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$db </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 /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE test (col1 string)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test VALUES ('a1')"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test VALUES ('a10')"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test VALUES ('a2')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createCollation</span><span style="color: #007700">(</span><span style="color: #DD0000">'NATURAL_CMP'</span><span style="color: #007700">, </span><span style="color: #DD0000">'strnatcmp'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$defaultSort </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT col1 FROM test ORDER BY col1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$naturalSort </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT col1 FROM test ORDER BY col1 COLLATE NATURAL_CMP"</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"Por omisión :\n"</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$defaultSort</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetchArray</span><span style="color: #007700">()){<br />    echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'col1'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br />echo </span><span style="color: #DD0000">"\nNatural :\n"</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$naturalSort</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetchArray</span><span style="color: #007700">()){<br />    echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'col1'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>El ejemplo anterior mostrará:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Por omisión :
a1
a10
a2

Natural :
a1
a2
a10</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-sqlite3.createcollation-seealso">
  <h3 class="title">Ver también</h3>
  <ul class="simplelist">
   <li>La documentación sobre la clasificación SQLite : <a href="http://sqlite.org/datatype3.html#collation" class="link external">&raquo;&nbsp;http://sqlite.org/datatype3.html#collation</a></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>