<table class="PHP">
<tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
<span class="xtra li2"><span class="de2">56
7
8
9
<span class="xtra li2"><span class="de2">1011
@H_403_5@</td>
<td class="de1"><pre class="de1"><span class="kw2"><?PHP
<span class="re0">$query <span class="sy0">= User<span class="sy0">::<span class="me2">find<span class="br0">(<span class="br0">)
<span class="sy0">-><span class="me1">where<span class="br0">(<span class="br0">[<span class="st_h">'id'<span class="sy0">=><span class="br0">[<span class="nu0">1<span class="sy0">,<span class="nu0">2<span class="sy0">,<span class="nu0">3<span class="sy0">,<span class="nu0">4<span class="br0">]<span class="br0">)
<span class="xtra li2"><span class="de2"> <span class="sy0">-><span class="me1">select<span class="br0">(<span class="br0">[<span class="st_h">'username'<span class="br0">]<span class="br0">)<span class="sy0">;
<span class="co1">// get the AR raw sql in YII2
<span class="re0">$commandQuery <span class="sy0">= clone <span class="re0">$query<span class="sy0">;
<span class="kw1">echo <span class="re0">$commandQuery<span class="sy0">-><span class="me1">createCommand<span class="br0">(<span class="br0">)<span class="sy0">-><span class="me1">getRawsql<span class="br0">(<span class="br0">)<span class="sy0">;
<span class="xtra li2"><span class="de2"> <span class="re0">$users <span class="sy0">= <span class="re0">$query<span class="sy0">-><span class="me1">all<span class="br0">(<span class="br0">)<span class="sy0">;@H_403_5@</td>
</tr></table>