<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.mysql-xdevapi-schema.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'mysql-xdevapi-schema.createcollection.php',
    1 => 'Schema::createCollection',
    2 => 'スキーマにコレクションを追加する',
  ),
  'up' => 
  array (
    0 => 'class.mysql-xdevapi-schema.php',
    1 => 'mysql_xdevapi\\Schema',
  ),
  'prev' => 
  array (
    0 => 'mysql-xdevapi-schema.construct.php',
    1 => 'Schema::__construct',
  ),
  'next' => 
  array (
    0 => 'mysql-xdevapi-schema.dropcollection.php',
    1 => 'Schema::dropCollection',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/mysql_xdevapi/mysql_xdevapi/schema/createcollection.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mysql-xdevapi-schema.createcollection" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Schema::createCollection</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">Schema::createCollection</span> &mdash; <span class="dc-title">スキーマにコレクションを追加する</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysql-xdevapi-schema.createcollection-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>mysql_xdevapi\Schema::createCollection</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="type"><a href="class.mysql-xdevapi-collection.php" class="type mysql_xdevapi\Collection">mysql_xdevapi\Collection</a></span></div>

  <p class="para rdfs-comment">
   スキーマ内にコレクションを作成します。
  </p>

  <div class="warning"><strong class="warning">警告</strong><p class="simpara">この関数は、
現在のところ詳細な情報はありません。引数のリストのみが
記述されています。</p></div>

 </div>


 <div class="refsect1 parameters" id="refsect1-mysql-xdevapi-schema.createcollection-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">name</code></dt>
    <dd>
     <p class="para">
      コレクションの名前。
     </p>
    </dd>
   
   
    <dt><code class="parameter">validate</code></dt>
    <dd>
     <p class="para">
      バリデーションの定義を JSON オブジェクトとして指定します。
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysql-xdevapi-schema.createcollection-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   コレクションオブジェクトを返します。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-mysql-xdevapi-schema.createcollection-changelog">
    <h3 class="title">変更履歴</h3>
    <table id="mysql-xdevapi-schema.createcollection.changelog" class="doctable informaltable">
     
      <thead>
       <tr>
        <th>バージョン</th>
        <th>説明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>8.0.20</td>
        <td>
         オプションの validate 引数が追加されました。
        </td>
       </tr>

      </tbody>
     
    </table>

 </div>


 <div class="refsect1 examples" id="refsect1-mysql-xdevapi-schema.createcollection-examples">
  <h3 class="title">例</h3>
  <div class="example" id="example-1">
   <p><strong>例1 <span class="methodname"><strong>mysql_xdevapi\Schema::createCollection()</strong></span> の例</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$session </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_xdevapi\getSession</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysqlx://user:password@localhost"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sql</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP DATABASE IF EXISTS food"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sql</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE DATABASE food"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sql</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE food.fruit(name text, rating text)"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$schema </span><span style="color: #007700">= </span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSchema</span><span style="color: #007700">(</span><span style="color: #DD0000">"food"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$schema</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createCollection</span><span style="color: #007700">(</span><span style="color: #DD0000">"trees"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$schema</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">gettables</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$schema</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getcollections</span><span style="color: #007700">());</span></span></code></div>
   </div>

   <div class="example-contents"><p>上の例の出力は、
たとえば以下のようになります。</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [fruit] =&gt; mysql_xdevapi\Table Object
        (
            [name] =&gt; fruit
        )
)
Array
(
    [trees] =&gt; mysql_xdevapi\Collection Object
        (
            [name] =&gt; trees
        )
)</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
    <p><strong>例2 <span class="methodname"><strong>mysql_xdevapi\Schema::createCollection()</strong></span> の例</strong></p>
    <div class="example-contents">
 <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /> $collection </span><span style="color: #007700">= </span><span style="color: #0000BB">$schema</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createCollection</span><span style="color: #007700">(</span><span style="color: #DD0000">"mycollection"</span><span style="color: #007700">, </span><span style="color: #DD0000">'{<br />    "validation": {<br />        "level": "strict",<br />        "schema": {<br />            "id": "http://json-schema.org/geo",<br />            "description": "A geographical coordinate",<br />            "type": "object",<br />            "properties": {<br />                "latitude": {<br />                    "type": "number"<br />                },<br />                "longitude": {<br />                    "type": "number"<br />                }<br />            },<br />            "required": ["latitude", "longitude"]<br />        }<br />    }<br />}'</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// Succeeds<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #DD0000">'{"latitude": 10, "longitude": 20}'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Fails, invalid types (not numbers)<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #DD0000">'{"latitude": "lat", "longitude": "long"}'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();</span></span></code></div>
    </div>

   </div>
 </div>


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