目次
1 構文
3.1 对比
3.2 and
3.3 or
3.4 not
3.5 between和not between
3.6 in和not in
3.7 like
3.8 exists
ホームページ バックエンド開発 PHPチュートリアル Yii2 クエリ where 条件アセンブリの詳細な説明

Yii2 クエリ where 条件アセンブリの詳細な説明

Mar 27, 2018 pm 01:41 PM
where yii2

<p>Yii2のクエリ条件に慣れたら、Activeを使用してください Record はデータのクエリに非常に便利です。 以下に、where()メソッドでの条件の組み立て方法を紹介します。 </p> <h2 id="構文">1 構文</h2> <p style="white-space:pre-wrap;">Yii2 は <code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb を使用します(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-built_in">where</span>()<code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-built_in">where</span>()</code>方法(当然还有其他方法)来实现条件筛选,语法:</code></p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>public $this where ( $condition, $params = [] )</pre><div class="contentsignin">ログイン後にコピー</div></div><p style="white-space:pre-wrap;"><code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-variable" style="color:rgb(223,80,0);">$params</span></code>为可选参数,指定要绑定查询的值。</p><p style="white-space:pre-wrap;"><code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-variable" style="color:rgb(223,80,0);">$condition</span></code>为必选参数,<code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-variable" style="color:rgb(223,80,0);">$condition</span></code>可以是字符串(如<code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-string" style="color:rgb(223,80,0);">&#39;id=1&#39;</span></code>)或者数组。</p><p style="white-space:pre-wrap;"><code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-variable" style="color:rgb(223,80,0);">$condition</span></code>メソッド (のもちろん他の方法もあります) 条件付きフィルタリングを実装するための構文: </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>column1=value1 AND column2=value2 AND ...</pre><div class="contentsignin">ログイン後にコピー</div></div><ul style="margin-top:0px;list-style-position:inside;" class=" list-paddingleft-2"><code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;パディング :.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-variable" style="color : rgb(223,80,0);">$params</span><li> はオプションのパラメータで、クエリにバインドされる値を指定します。 <p><code class="hljs json" style="font-family:Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;white-space:pre-wrap;"><code class="hljs bash" style="font-family:Consolas、'Liberation Mono'、Menlo、Courier、monospace;font-size:12px;padding:.3em;color:rgb(51,51,51 );background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-variable" style="color:rgb(223,80,0);">$condition </span></code> は必須パラメータです。<code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color :rgb(51,51,51);背景色:rgb(247,247,247);表示:インライン;行の高さ:1.65;"><span class="hljs-variable" style="color:rgb(223,80) ,0);">$condition</span></p> は文字列 (<code class="hljs bash" style="font-family:Consolas、'Liberation Mono'、Menlo、Courier、monospace;font- など) にすることができます。サイズ:12px;パディング:.3em;色:rgb(51,51,51);背景色:rgb(247,247,247);表示:インライン;行の高さ:1.65;"><span class="hljs-string" style ="color:rgb(223,80,0);">'id=1'</span></li>) または配列。 <li><p><code class="hljs bash" style="font-family:Consolas、'Liberation Mono'、Menlo、Courier、monospace;font-size:12px;padding:.3em;color:rgb(51,51,51 );background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-variable" style="color:rgb(223,80,0);">$condition </span> <code class="hljs json" style="font-family:Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;white-space:pre-wrap;"> が配列の場合、次の 2 つの形式があります: </code></p></li></ul>ハッシュ形式: <h2 style="font-family:'Microsoft YaHei UI Light', SimHei, SimSun, sans-serif;line-height:1.1;color:rgb(66,139,209);">['column1' => 値 1, '列 2' => 値 2, ...]</h2><p style="white-space:pre-wrap;"></p><p style="white-space:pre-wrap;"> 演算子の形式: <code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">IN</code>语句。</p><p style="white-space:pre-wrap;">如果某个值为<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-literal" style="color:rgb(0,134,179);">null</span></code>,会用<code class="hljs cpp" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">IS<span class="hljs-literal" style="color:rgb(0,134,179);">NULL</span></code>[演算子, operand1, operand2, ...]</p><p style="white-space:pre-wrap;"></p><h2 style="font-family:'Microsoft YaHei UI Light', SimHei, SimSun, sans-serif;line-height:1.1;color:rgb(66,139,209);"></h2>2 ハッシュ形式<p style="white-space:pre-wrap;"></p>通常、ハッシュ形式のクエリ条件は次のような SQL ステートメントを生成します:🎜<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;type&#39; => 1, &#39;status&#39; => 2] // 生成:(type = 1) AND (status = 2)[&#39;id&#39; => [1, 2, 3], &#39;status&#39; => 2] // 生成:(id IN (1, 2, 3)) AND (status = 2)[&#39;status&#39; => null] // 生成:status IS NULL</pre><div class="contentsignin">ログイン後にコピー</div></div>🎜 値が配列の場合、<code class= が生成されます"hljs" style="font-family:Consolas、'Liberation Mono'、Menlo、Courier、monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb (247,247,247);display:inline;line-height:1.65;">IN🎜 ステートメント。 🎜🎜値が <code class="hljs Coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb( 51 ,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-literal" style="color:rgb(0,134,179);">null < /span>🎜、<code class="hljs cpp" style="font-family:Consolas、'Liberation Mono'、Menlo、Courier、monospace;font-size:12px;padding:.3em;color:rgb ( 51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">IS<span class="hljs-literal" style="color:rgb(0,134,179);" > NULL🎜 ステートメントを生成します。 🎜🎜例: 🎜<div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&amp;#39;&gt;&amp;#39;, &amp;#39;id&amp;#39;, 1] // 生成:id &gt; 1[&amp;#39;&lt;&amp;#39;, &amp;#39;id&amp;#39;, 100] // 生成:id &lt; 100[&amp;#39;=&amp;#39;, &amp;#39;id&amp;#39;, 10] // 生成:id = 10[&amp;#39;&gt;=&amp;#39;, &amp;#39;id&amp;#39;, 1] // 生成:id &gt;= 1[&amp;#39;&lt;=&amp;#39;, &amp;#39;id&amp;#39;, 100] // 生成:id != 10</pre><div class="contentsignin">ログイン後にコピー</div></div><div class="contentsignin">ログイン後にコピー</div></div>🎜3 演算子形式🎜🎜 演算子形式では、Yii は指定された演算子に基づいて SQL ステートメントを生成します。 🎜<p style="white-space:pre-wrap;">运算符有:<code class="hljs coffeescript" style="font-family:Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">and</span></code>、<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">or</span></code>、<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">not</span></code>、<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">between</code>、<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">ではありません</span> between</code>、<code class="hljs bash" style="font-family:Consolas、'Liberation Mono'、Menlo、Courier、monospace;font-size:12px;padding:.3em;color:rgb(51,51, 51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><code class="hljs bash" style="font-family:Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">in</span></code>、<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">not</span><span class="hljs-keyword" style="color:rgb(167,29,93);">in</span></code>、<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">like</code>in<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">、</span></code>not<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">in</span></code>、<code class="hljs" style="font-ファミリ:Consolas、'Liberation Mono'、Menlo、Courier、等幅;フォントサイズ:12px;パディング:.3em;カラー:rgb(51,51,51);背景色:rgb(247,247,247);表示:インライン; line-height:1.65;">いいね<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">or</span><span class="hljs-keyword" style="color:rgb(167,29,93);">not</span> like</code>、<code class="hljs perl" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">exists</span></code>、<code class="hljs perl" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">or</span> いいね<span class="hljs-keyword" style="color:rgb(167,29,93);">、</span>🎜違う🎜 🎜、🎜🎜または🎜🎜ない🎜好き🎜、🎜🎜存在する🎜🎜、🎜🎜ない🎜🎜存在する🎜</code>、<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">></code>、<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><</code>、<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">=</code>、<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">>=</code>、<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><=</code>、<code class="hljs diff" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-addition" style="color:rgb(85,165,50);background-color:rgb(234,255,234);">!=</span></code>等。</p><h3 id="对比">3.1 对比</h3><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;>&#39;, &#39;id&#39;, 1] // 生成:id > 1[&#39;<&#39;, &#39;id&#39;, 100] // 生成:id < 100[&#39;=&#39;, &#39;id&#39;, 10] // 生成:id = 10[&#39;>=&#39;, &#39;id&#39;, 1] // 生成:id >= 1[&#39;<=&#39;, &#39;id&#39;, 100] // 生成:id != 10</pre><div class="contentsignin">ログイン後にコピー</div></div><div class="contentsignin">ログイン後にコピー</div></div><p style="white-space:pre-wrap;">具体生成的SQL语句,运算符<code class="hljs objectivec" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">id</span></code>会自动加上反斜杠引号<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">`</code>,运算数会自动转义。</p><h3 id="and">3.2 and</h3><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;and&#39;, &#39;id&#39; => 1, &#39;id&#39; => 2] // 生成:id=1 AND id=2[&#39;and&#39;, &#39;id=1&#39;, &#39;id=2&#39;] // 生成:id=1 AND id=2[&#39;and&#39;, &#39;type=1&#39;, [&#39;or&#39;, &#39;id=1&#39;, &#39;id=2&#39;]] // 生成:type=1 AND (id=1 OR id=2)</pre><div class="contentsignin">ログイン後にコピー</div></div><p style="white-space:pre-wrap;">在第2条和第3条语句中,列名称和搜索值未用键值关系指定,所以生成的SQL不会添加引号,也不会转义。</p><h3 id="or">3.3 or</h3><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;or&#39;, [&#39;type&#39; => [7, 8, 9]], [&#39;id&#39; => [1, 2, 3]]] // 生成:(type IN (7, 8, 9) OR (id IN (1, 2, 3)))</pre><div class="contentsignin">ログイン後にコピー</div></div><h3 id="not">3.4 not</h3><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;not&#39;, [&#39;attribute&#39; => null]] // 生成:NOT (attribute IS NULL)</pre><div class="contentsignin">ログイン後にコピー</div></div><h3 id="between和not-between">3.5 between和not between</h3><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;between&#39;, &#39;id&#39;, 1, 10] // 生成:id BETWEEN 1 AND 10[&#39;not between&#39;, &#39;id&#39;, 1, 10] // 生成:id NOT BETWEEN 1 AND 10</pre><div class="contentsignin">ログイン後にコピー</div></div><p style="white-space:pre-wrap;">运算符后面的运算数1为数据表<span style="font-weight:bolder;">列名称</span>,运算数2和运算数3分别为列值范围的<span style="font-weight:bolder;">最小值</span>和<span style="font-weight:bolder;">最大值</span>。</p><h3 id="in和not-in">3.6 in和not in</h3><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;in&#39;, &#39;id&#39;, [1, 2, 3]] // 生成:id IN (1, 2, 3)[&#39;not in&#39;, &#39;id&#39;, [1, 2, 3]] // 生成:id NOT IN (1, 2, 3)</pre><div class="contentsignin">ログイン後にコピー</div></div><p style="white-space:pre-wrap;">运算符后面的<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">运算数1</code>为列名称或DB表达式,<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">运算数2</code>为数组,指定列值所在的范围。</p><p style="white-space:pre-wrap;">这个方法会为值添加引号,并正确转义。</p><p style="white-space:pre-wrap;">要生成混合<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">IN</code>条件,列名和列值都设置为数组,并且用列名为列值指定下标:</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;in&#39;, [&#39;id&#39;, &#39;name&#39;], [[&#39;id&#39; => 1, &#39;name&#39; => &#39;foo&#39;], [&#39;id&#39; => 2, &#39;name&#39; => &#39;bar&#39;]]] // 生成:(`id`, `name`) IN ((1, &#39;foo&#39;), (2, &#39;bar&#39;))</pre><div class="contentsignin">ログイン後にコピー</div></div><p style="white-space:pre-wrap;">另外,还可以用子查询作为<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">IN</code>条件的值,如下:</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;in&#39;, &#39;user_id&#39;, (new Query())->select(&#39;id&#39;)->from(&#39;users&#39;)->where([&#39;active&#39; => 1])]</pre><div class="contentsignin">ログイン後にコピー</div></div><h3 id="like">3.7 like</h3><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;like&#39;, &#39;name&#39;, &#39;tester&#39;] // 生成:name LIKE &#39;%tester%&#39;[&#39;like&#39;, &#39;name&#39;, [&#39;test&#39;, &#39;sample&#39;]] // 生成:name LIKE &#39;%test%&#39; AND name LIKE &#39;%sample%&#39;[&#39;like&#39;, &#39;name&#39;, &#39;%tester&#39;, false] // 生成:name LIKE &#39;%tester&#39; // 这是自定义查询方式,要传入值为false的运算数3,并且自行添加%</pre><div class="contentsignin">ログイン後にコピー</div></div><p style="white-space:pre-wrap;"><span style="color:rgb(119,119,119);font-family:'courier new';"><span style="background-color:rgb(238,238,238);">运算数</span></span>后面的运算数1为列名称或DB表达式,运算数2为字符串或数组,指定列值查询条件。</p><p style="white-space:pre-wrap;">这个方法会为值添加引号,并正确转义。</p><p style="white-space:pre-wrap;"><code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">or</span> like</code>、<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">not</span> like</code>、<code class="hljs coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">or</span><span class="hljs-keyword" style="color:rgb(167,29,93);">not</span> like</code>用法和<code class="hljs" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;">like</code>一样。</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;or like&#39;, &#39;name&#39;, [&#39;test&#39;, &#39;sample&#39;]] // 生成:name LIKE &#39;%test%&#39; OR name LIKE &#39;%sample%&#39;[&#39;not like&#39;, &#39;name&#39;, &#39;tester&#39;] // 生成:name NOT LIKE &#39;%tester%&#39;[&#39;or not like&#39;, &#39;name&#39;, [&#39;test&#39;, &#39;sample&#39;]] // 生成:name NOT LIKE &#39;%test%&#39; OR name NOT LIKE &#39;%sample%&#39;</pre><div class="contentsignin">ログイン後にコピー</div></div><h3 id="exists">3.8 exists</h3><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>[&#39;exists&#39;, (new Query())->select(&#39;id&#39;)->from(&#39;users&#39;)->where([&#39;active&#39; => 1])] // 生成:EXISTS (SELECT "id" FROM "users" WHERE "active"=1)</pre><div class="contentsignin">ログイン後にコピー</div></div><p style="white-space:pre-wrap;"><code class="hljs perl" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">not</span><span class="hljs-keyword" style="color:rgb(167,29,93);">exists</span></code>用法和<code class="hljs perl" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb(51,51,51);background-color:rgb(247,247,247);display:inline;line-height:1.65;"><span class="hljs-keyword" style="color:rgb(167,29,93);">exists</span></code>一样。</p> <p style="white-space: pre-wrap;"> 相关推荐:</p> <p style="white-space: pre-wrap;"><a href="http://www.php.cn/php-weizijiaocheng-330818.html" target="_self">Yii20中文开发向导——Where条件查询全解析</a></p>

以上がYii2 クエリ where 条件アセンブリの詳細な説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

yii2でjqueryを削除する方法 yii2でjqueryを削除する方法 Feb 17, 2023 am 09:55 AM

yii2 から jquery を削除する方法: 1. AppAsset.php ファイルを編集し、変数 $depends の「yii\web\YiiAsset」値をコメント アウトします; 2. main.php ファイルを編集し、設定「'yii」を以下に追加しますフィールド「components」\web\JqueryAsset' => ['js' => [],'sourcePath' => null,]," を使用して jquery スクリプトを削除します。

Laravel コレクションの Where メソッドの実践ガイド Laravel コレクションの Where メソッドの実践ガイド Mar 10, 2024 pm 04:36 PM

Laravel コレクションの Where メソッドに関する実践ガイド Laravel フレームワークの開発中、コレクションは、データを操作するための豊富なメソッドを提供する非常に便利なデータ構造です。中でも、Where メソッドは、指定した条件に基づいてコレクション内の要素をフィルタリングできる、一般的に使用されるフィルタリング メソッドです。この記事では、Laravel コレクションでの Where メソッドの使用法を紹介し、特定のコード例を通じてその使用法を示します。 1. Whereメソッドの基本的な使い方

LaravelコレクションでWhereメソッドを使用する方法 LaravelコレクションでWhereメソッドを使用する方法 Mar 10, 2024 pm 10:21 PM

Laravel コレクションで Where メソッドを使用する方法 Laravel は、開発者がアプリケーションを迅速に構築できるようにする豊富な機能とツールを提供する人気のある PHP フレームワークです。その中でも、コレクションは Laravel の非常に実用的で強力なデータ構造であり、開発者はコレクションを使用して、フィルタリング、マッピング、並べ替えなどのデータに対するさまざまな操作を実行できます。コレクションでは、Where メソッドは、指定された条件に基づいてコレクションをフィルター処理するためによく使用される方法です。

初心者から熟練者まで: is セレクターと where セレクターの使用スキルをマスターする 初心者から熟練者まで: is セレクターと where セレクターの使用スキルをマスターする Sep 08, 2023 am 09:15 AM

初心者から上級者まで: is および where セレクターの使用スキルをマスターする はじめに: データの処理と分析のプロセスにおいて、セレクターは非常に重要なツールです。セレクターを使用すると、特定の条件に従ってデータセットから必要なデータを抽出できます。この記事では、読者がこれら 2 つのセレクターの強力な機能をすぐに習得できるように、is および where セレクターの使用スキルを紹介します。 1. is セレクターの使用 is セレクターは、与えられた条件に基づいてデータセットを選択できるようにする基本的なセレクターです。

いくつかの厳選された CTF 演習は、yii2 フレームワークの学習に役立ちます。 いくつかの厳選された CTF 演習は、yii2 フレームワークの学習に役立ちます。 Feb 23, 2022 am 10:33 AM

この記事では、yii2 フレームワークについて紹介し、いくつかの CTF 演習を共有し、それを使用して yii2 フレームワークを学習します。

mysql left joinの基本的な使い方とonとwhereの違い mysql left joinの基本的な使い方とonとwhereの違い Jun 02, 2023 pm 11:54 PM

はじめに SQL ステートメントを作成する場合、内部接続や外部接続などの接続キーワードの使用を避けることはできません。多くのタイプがあります。他の場所で見つけた画像をここに掲載します。この画像は非常に詳細だと思います。SQL ステートメントの一般的なリンク タイプを示しています。この記事の leftjoin を例として取り上げます。オンラインで入手できます。定義されているとおり: LEFTJOIN キーワードは、右側のテーブルに一致する行がない場合でも、左側のテーブルのすべての行を返します。実際、左結合は文字どおり比較的理解しやすいのですが、on以降とwhere以降では結果が全く異なるなど、使用上の問題点もいくつかあります。

YII2 フレームワークを使用して Redis 拡張機能をインストールする方法 YII2 フレームワークを使用して Redis 拡張機能をインストールする方法 May 26, 2023 pm 06:41 PM

1. yii2-redis のマスター ブランチの Windows バージョンを、composer でダウンロードする必要があります。 2. 解凍して、vendor/yiisoft にコピーします。 3. 'yiisoft/yii2-redis'=>array('name'=>'yiisoft) を追加します。 yiisoft /yii2-redis','version'=>'2.0 の extensions.php にコピーします。

LaravelコレクションのWhereメソッドの使用状況分析 LaravelコレクションのWhereメソッドの使用状況分析 Mar 09, 2024 pm 06:51 PM

Laravel は豊富で便利な機能を提供する人気の PHP 開発フレームワークであり、コレクションは Laravel の非常に重要なデータ構造の 1 つです。コレクション クラスには多くの強力なメソッドが用意されており、その 1 つが where メソッドです。この記事では、特定のコード例を使用して、Laravel コレクションでの where メソッドの使用法を分析します。 1. コレクションを作成する まず、いくつかのデータを含むコレクションを作成する必要があります。できる

See all articles