목차
1 구문
2 哈希格式
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 쿼리에 대한 자세한 설명

조건조립이 이루어지는 Yii2 쿼리에 대한 자세한 설명

Mar 27, 2018 pm 01:41 PM
where yii2

<p>Yii2의 쿼리 조건을 숙지한 후 Active를 사용하세요. 레코드는 데이터 쿼리에 매우 편리합니다. 아래에서는 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">여기서</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-built_in">where</span>()</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><ul style="margin-top:0px;list-style-position:inside;" class=" list-paddingleft-2"><li><p>哈希格式:<code class="hljs json" 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;white-space:pre-wrap;">[&#39;column1&#39; => value1, &#39;column2&#39; => value2, ...]</code></p></li><li><p>运算符格式:<code class="hljs json" 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;white-space:pre-wrap;">[operator, operand1, operand2, ...]</code></p></li></ul><h2 id="哈希格式">2 哈希格式</h2><p style="white-space:pre-wrap;">通常,哈希格式的查询条件生成这样的SQL语句:</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><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><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></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" 스타일 = "color:rgb(223,80,0);">$params</span></code>는 쿼리에 바인딩할 값을 지정하는 선택적 매개변수입니다. <p style="white-space:pre-wrap;"></p><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);디스플레이:inline;line-height:1.65;"><span class="hljs-variable" style="color:rgb(223,80,0);">$조건 </span></code>는 필수 매개변수입니다. <code class="hljs bash" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:. 3em;색상:rgb(51,51,51);배경색:rgb(247,247,247);디스플레이: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 클래스 = "hljs-string" style="color:rgb(223,80,0);">'id=1'</span></code>) 또는 배열. <h2 style="font-family:'Microsoft YaHei UI Light', SimHei, SimSun, sans-serif;line-height:1.1;color:rgb(66,139,209);"></h2><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);디스플레이:inline;line-height:1.65;"><span class="hljs-variable" style="color:rgb(223,80,0);">$조건 </span></code> 배열인 경우 두 가지 형식이 있습니다: <p style="white-space:pre-wrap;"><ul style="margin-top:0px;list-style-position:inside;" <li ></p>해시 형식: <code class="hljs json" 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;white-space:pre-wrap;">['column1' => value1, 'column2' => value2, ...]</code>🎜</li><li>🎜연산자 형식: <code class="hljs json" 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;white-space:pre-wrap;">[연산자, Operand1, Operand2, ...]</code>🎜</li></ul>🎜2 해시 형식🎜🎜일반적으로 해시 형식의 쿼리 조건은 다음과 같은 SQL 문을 생성합니다.🎜<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>🎜특정 값이 배열을 사용하면 <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> 문. 🎜🎜값이 <code class="hljs Coffeescript" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px;padding:.3em;color:rgb( 51 ,51,51);배경색:rgb(247,247,247);디스플레이: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> 명령문을 생성합니다. 🎜🎜예: 🎜<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;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><div class="contentsignin">로그인 후 복사</div></div>🎜3 연산자 형식🎜🎜연산자 형식에서 Yii는 지정된 연산자를 기반으로 SQL 문을 생성합니다. 🎜<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);">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);">not</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;"><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>、<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 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);">not</span><span class="hljs-keyword" style="color:rgb(167,29,93);">exists</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;"><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><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 쿼리에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 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 Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 채팅 명령 및 사용 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

yii2에서 jquery를 제거하는 방법 yii2에서 jquery를 제거하는 방법 Feb 17, 2023 am 09:55 AM

yii2에서 jquery를 제거하는 방법: 1. AppAsset.php 파일을 편집하고 $dependents 변수의 "yii\web\YiiAsset" 값을 주석 처리합니다. 2. main.php 파일을 편집하고 구성을 "'yii"로 추가합니다. "comComponents" \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 선택기의 사용 기술을 소개합니다. 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은 문자 그대로 이해하기 쉽지만 사용 중에 여전히 몇 가지 문제가 있습니다. 예를 들어 조건이 where 이후인 경우 결과가 얕은 것에서 깊은 것으로 가보겠습니다.

YII2 프레임워크를 사용하여 Redis 확장을 설치하는 방법 YII2 프레임워크를 사용하여 Redis 확장을 설치하는 방법 May 26, 2023 pm 06:41 PM

1. Composer가 포함된 yii2-redis 마스터 브랜치의 Windows 버전을 다운로드해야 합니다. 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에서 매우 중요한 데이터 구조 중 하나입니다. 컬렉션 클래스는 많은 강력한 메서드를 제공하며 그 중 하나가 where 메서드입니다. 이 문서에서는 특정 코드 예제를 사용하여 Laravel 컬렉션에서 where 메소드의 사용법을 분석합니다. 1. 컬렉션 생성 먼저 일부 데이터가 포함된 컬렉션을 생성해야 합니다. 할 수 있다

See all articles