downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the Git repository for this website on git.php.net.

Source of: /manual/es/mongo.sqltomongo.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/mongo.manual.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'es',
  ),
 
'this' =>
  array (
   
0 => 'mongo.sqltomongo.php',
   
1 => 'Tabla de correlaci&oacute;n de SQL a Mongo',
  ),
 
'up' =>
  array (
   
0 => 'mongo.manual.php',
   
1 => 'Manual',
  ),
 
'prev' =>
  array (
   
0 => 'mongo.writeconcerns.php',
   
1 => 'Asuntos de Escritura (Write Concerns)',
  ),
 
'next' =>
  array (
   
0 => 'mongo.connecting.php',
   
1 => 'Conexi&oacute;n',
  ),
 
'alternatives' =>
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="mongo.sqltomongo" class="chapter">
 <h1>Tabla de correlación de SQL a Mongo</h1>

 <p class="para">
  Esta es una versión específica de PHP de la tabla de correlación de
  <a href="http://docs.mongodb.org/manual/reference/sql-comparison/" class="link external">&raquo;&nbsp;SQL a Mongo</a>
  de la documentación principal.
 </p>
 <p class="para">
  <table class="doctable informaltable">
  
    <thead>
     <tr>
      <th>Sentencia SQL</th>
      <th>Sentencia en el Lenguaje de Consulta Mongo</th>
     </tr>

    </thead>

   
    <tbody class="tbody">
     <tr>
      <td>
       <em>CREATE TABLE USERS (a Number, b Number)</em>
      </td>
      <td>
       Implícito, o utilice  <span class="function"><a href="mongodb.createcollection.php" class="function">MongoDB::createCollection()</a></span>.
      </td>
     </tr>

     <tr>
      <td>
       <em>INSERT INTO USERS VALUES(1,1)</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;insert(array(&quot;a&quot; =&gt; 1, &quot;b&quot; =&gt; 1));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT a,b FROM users</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(), array(&quot;a&quot; =&gt; 1, &quot;b&quot; =&gt; 1));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users WHERE age=33</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;age&quot; =&gt; 33));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT a,b FROM users WHERE age=33</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;age&quot; =&gt; 33), array(&quot;a&quot; =&gt; 1, &quot;b&quot; =&gt; 1));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT a,b FROM users WHERE age=33 ORDER BY name</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;age&quot; =&gt; 33), array(&quot;a&quot; =&gt; 1, &quot;b&quot; =&gt; 1))-&gt;sort(array(&quot;name&quot; =&gt; 1));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users WHERE age&gt;33</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;age&quot; =&gt; array(&#039;$gt&#039; =&gt; 33)));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users WHERE age&lt;33</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;age&quot; =&gt; array(&#039;$lt&#039; =&gt; 33)));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users WHERE name LIKE &quot;%Joe%&quot;</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;name&quot; =&gt; new MongoRegex(&quot;/Joe/&quot;)));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users WHERE name LIKE &quot;Joe%&quot;</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;name&quot; =&gt; new MongoRegex(&quot;/^Joe/&quot;)));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users WHERE age&gt;33 AND age&lt;=40</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;age&quot; =&gt; array(&#039;$gt&#039; =&gt; 33, &#039;$lte&#039; =&gt; 40)));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users ORDER BY name DESC</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find()-&gt;sort(array(&quot;name&quot; =&gt; -1));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>CREATE INDEX myindexname ON users(name)</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;ensureIndex(array(&quot;name&quot; =&gt; 1));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>CREATE INDEX myindexname ON users(name,ts DESC)</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;ensureIndex(array(&quot;name&quot; =&gt; 1, &quot;ts&quot; =&gt; -1));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users WHERE a=1 and b=&#039;q&#039;</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;a&quot; =&gt; 1, &quot;b&quot; =&gt; &quot;q&quot;));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users LIMIT 10 SKIP 20</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find()-&gt;limit(10)-&gt;skip(20);</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users WHERE a=1 or b=2</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&#039;$or&#039; =&gt; array(array(&quot;a&quot; =&gt; 1), array(&quot;b&quot; =&gt; 2))));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT * FROM users LIMIT 1</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find()-&gt;limit(1);</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>EXPLAIN SELECT * FROM users WHERE z=3</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;z&quot; =&gt; 3))-&gt;explain()</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT DISTINCT last_name FROM users</em>
      </td>
      <td>
       <em>$db-&gt;command(array(&quot;distinct&quot; =&gt; &quot;users&quot;, &quot;key&quot; =&gt; &quot;last_name&quot;));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT COUNT(*y) FROM users</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;count();</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT COUNT(*y) FROM users where AGE &gt; 30</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;age&quot; =&gt; array(&#039;$gt&#039; =&gt; 30)))-&gt;count();</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>SELECT COUNT(AGE) from users</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;find(array(&quot;age&quot; =&gt; array(&#039;$exists&#039; =&gt; true)))-&gt;count();</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>UPDATE users SET a=1 WHERE b=&#039;q&#039;</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;update(array(&quot;b&quot; =&gt; &quot;q&quot;), array(&#039;$set&#039; =&gt; array(&quot;a&quot; =&gt; 1)));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>UPDATE users SET a=a+2 WHERE b=&#039;q&#039;</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;update(array(&quot;b&quot; =&gt; &quot;q&quot;), array(&#039;$inc&#039; =&gt; array(&quot;a&quot; =&gt; 2)));</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>DELETE FROM users WHERE z=&quot;abc&quot;</em>
      </td>
      <td>
       <em>$db-&gt;users-&gt;remove(array(&quot;z&quot; =&gt; &quot;abc&quot;));</em>
      </td>
     </tr>

    </tbody>
  
  </table>

 </p>
</div>
<?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites