Sophie

Sophie

distrib > Mageia > 7 > armv7hl > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 10398

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>Create collection index</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysql-xdevapi-collection.count.html">Collection::count</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysql-xdevapi-collection.dropindex.html">Collection::dropIndex</a></div>
 <div class="up"><a href="class.mysql-xdevapi-collection.html">mysql_xdevapi\Collection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mysql-xdevapi-collection.createindex" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Collection::createIndex</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">Collection::createIndex</span> &mdash; <span class="dc-title">Create collection index</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysql-xdevapi-collection.createindex-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>mysql_xdevapi\Collection::createIndex</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$index_name</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$index_desc_json</code></span>
   )</div>

  <p class="para rdfs-comment">
    Creates an index on the collection.
  </p>
  <p class="para">
    An exception is thrown if an index with the same name already exists,
    or if index definition is not correctly formed.
   </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mysql-xdevapi-collection.createindex-parameters">
  <h3 class="title">Parameters</h3>
  <dl>

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

    <dd>

     <p class="para">
      The name of the index that to create. This name must be a valid index name as 
      accepted by the <em>CREATE INDEX</em> SQL query.
     </p>
    </dd>

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

    <dd>

     <p class="para">
      Definition of the index to create. It contains an array of IndexField objects,
      and each object describes a single document member to include in the index, 
      and an optional string for the type of index that might be INDEX (default) or SPATIAL.
     </p>
     <p class="para">
      A single IndexField description consists of the following fields:
     </p>
     <ul class="itemizedlist">
      <li class="listitem">
        <p class="para">
          <code class="code">field</code>: string, the full document path to the document member or field to be indexed.
        </p>
      </li>
      <li class="listitem">
       <p class="para">
        <code class="code">type</code>: string, one of the supported SQL column types to map the field into.
        For numeric types, the optional UNSIGNED keyword may follow.
        For the TEXT type, the length to consider for indexing may be added.
       </p>
      </li>
      <li class="listitem">
        <p class="para">
          <code class="code">required</code>: bool, (optional) true if the field is required to exist in the document. 
          Defaults to <strong><code>FALSE</code></strong>, except for <em>GEOJSON</em> where it defaults to <strong><code>TRUE</code></strong>.
         </p>
       </li>
      <li class="listitem">
        <p class="para">
          <code class="code">options</code>: integer, (optional) special option flags for use 
          when decoding <em>GEOJSON</em> data.
        </p>
      </li>
      <li class="listitem">
        <p class="para">
          <code class="code">srid</code>: integer, (optional) srid value for use when 
          decoding <em>GEOJSON</em> data.
        </p>
      </li>
      </ul>

      <p class="para">
        It is an error to include other fields not described above in 
        IndexDefinition or IndexField documents.
      </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysql-xdevapi-collection.createindex-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
 </div>


 <div class="refsect1 examples" id="refsect1-mysql-xdevapi-collection.createindex-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1983">
   <p><strong>Example #1 <span class="function"><strong>mysql_xdevapi\Collection::createIndex()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$session&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_xdevapi</span><span style="color: #007700">\</span><span style="color: #0000BB">getSession</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysqlx://user:password@localhost"</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">"DROP&nbsp;DATABASE&nbsp;IF&nbsp;EXISTS&nbsp;addressbook"</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&nbsp;DATABASE&nbsp;addressbook"</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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</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">"addressbook"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$collection&nbsp;</span><span style="color: #007700">=&nbsp;</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">"people"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Creating&nbsp;a&nbsp;text&nbsp;index<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createIndex</span><span style="color: #007700">(<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'myindex1'</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'{"fields":&nbsp;[{<br />&nbsp;&nbsp;&nbsp;&nbsp;"field":&nbsp;"$.name",&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"TEXT(25)",&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;"required":&nbsp;true}],&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;"unique":&nbsp;false}'<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;A&nbsp;spatial&nbsp;index<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createIndex</span><span style="color: #007700">(<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'myindex2'</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'{"fields":&nbsp;[{<br />&nbsp;&nbsp;&nbsp;&nbsp;"field":&nbsp;"$.home",&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"GEOJSON",&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;"required":&nbsp;true}],&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"SPATIAL"}'<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysql-xdevapi-collection.count.html">Collection::count</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysql-xdevapi-collection.dropindex.html">Collection::dropIndex</a></div>
 <div class="up"><a href="class.mysql-xdevapi-collection.html">mysql_xdevapi\Collection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>