YII2 程序内获取 ActiveRecord 所执行的 SQL 语句

前端之家收集整理的这篇文章主要介绍了YII2 程序内获取 ActiveRecord 所执行的 SQL 语句前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<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>

猜你在找的程序笔记相关文章