首頁 > 後端開發 > php教程 > laravel DB 連線查詢取別名出錯了,table不存在

laravel DB 連線查詢取別名出錯了,table不存在

WBOY
發布: 2016-08-04 09:21:19
原創
1372 人瀏覽過

<code>DB::table('topics')->select('topics.*', 'b.username',
            'b.avatar', 'c.username as rname', 'd.cname')
            ->where('topics.is_hidden', 0)
            ->leftJoin('users b', 'b.uid', '=', 'topics.uid')
            ->leftJoin('users c', 'c.uid', '=', 'topics.ruid')
            ->leftJoin('nodes d', 'd.node_id', '=', 'topics.node_id')
            ->orderBy('ord', 'desc')
            ->take($limit)->get();
</code>
登入後複製
登入後複製

連線查詢取別名錯了
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'startbbs.stb_users b' doesn't exist (SQL: select stb_users b' doesn't exist (SQL: select stb_topics b' doesn't exist/s. stb_b.avatar, stb_c.username as rname, stb_d.cname stb_d. on stb_b.uid = stb_topics. uid left join stb_users c on stb_c.uid = stb_topics.ruid = stb_topics. node_id = stb_topics.node_id where stb_topics .is_hidden = 0 order by ord desc limit 20) 回覆內容: <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">&lt;code&gt;DB::table('topics')-&gt;select('topics.*', 'b.username', 'b.avatar', 'c.username as rname', 'd.cname') -&gt;where('topics.is_hidden', 0) -&gt;leftJoin('users b', 'b.uid', '=', 'topics.uid') -&gt;leftJoin('users c', 'c.uid', '=', 'topics.ruid') -&gt;leftJoin('nodes d', 'd.node_id', '=', 'topics.node_id') -&gt;orderBy('ord', 'desc') -&gt;take($limit)-&gt;get(); &lt;/code&gt;</pre><div class="contentsignin">登入後複製</div></div><div class="contentsignin">登入後複製</div></div> 連線查詢取別名錯了SQLSTATE[42S02]: Base table or view not found: 1146 Table 'startbbs.stb_users b' doesn't exist (SQL: select stb_users b' doesn't exist (SQL: select

stb_topics b' doesn't exist/s. stb_b

.

avatar

,
stb_c.username as rname, stb_d.cname stb_d. on stb_b.uid = stb_topics. uid left join stb_users c on stb_c.uid = stb_topics.ruid = stb_topics. node_id = stb_topics.node_id where stb_topics .is_hidden = 0 order by ord desc limit 20) 最好的做法是把這SQL複製到資料庫管理工具中執行下,看看是否是你建構的有問題 從你建構的sql看,是因為別名加上了表前綴'stb'

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板