<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'sqlite3.createcollation.php',
    1 => 'SQLite3::createCollation',
    2 => 'SQLのcollate関数として使うPHP関数を登録する',
  ),
  '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' => 'ja',
    '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">SQLのcollate関数として使うPHP関数を登録する</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-sqlite3.createcollation-description">
  <h3 class="title">説明</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">
   SQL文の中でcollate関数として使うPHP関数、またはユーザー定義の関数を登録します。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-sqlite3.createcollation-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">name</code></dt>
    <dd>
     <p class="para">
      作成、または再定義するSQL collate 関数の名前
     </p>
    </dd>
   
   
    <dt><code class="parameter">callback</code></dt>
    <dd>
     <p class="para">
      collation の振る舞いを定義する、PHP関数または、
      コールバックとして適用するユーザー定義関数。
      2つの値を受けとり、<span class="function"><a href="function.strcmp.php" class="function">strcmp()</a></span>
      関数が返すのと同じ値を返します。つまり、
      はじめの文字列が前の文字列より前にソートされる場合に-1、
      後にソートされる場合に1、等しい場合に0を返します。
     </p>
      <p class="para">
       この関数は、以下のように定義されるべきです:
       <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">戻り値</h3>
  <p class="para">
   成功した場合に <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> を、失敗した場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3.createcollation-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>SQLite3::createCollation()</strong></span> の例</strong></p>
    <div class="example-contents"><p>
     SQLite3 データベースの中で、シーケンスを並べる
     <span class="function"><a href="function.strnatcmp.php" class="function">strnatcmp()</a></span> 関数を登録します。
    </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">"default:\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>上の例の出力は以下となります。</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">default:
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">参考</h3>
  <ul class="simplelist">
   <li>SQLite collation ドキュメント: <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); ?>