1. <i id='NA5tI'><tr id='NA5tI'><dt id='NA5tI'><q id='NA5tI'><span id='NA5tI'><b id='NA5tI'><form id='NA5tI'><ins id='NA5tI'></ins><ul id='NA5tI'></ul><sub id='NA5tI'></sub></form><legend id='NA5tI'></legend><bdo id='NA5tI'><pre id='NA5tI'><center id='NA5tI'></center></pre></bdo></b><th id='NA5tI'></th></span></q></dt></tr></i><div id='NA5tI'><tfoot id='NA5tI'></tfoot><dl id='NA5tI'><fieldset id='NA5tI'></fieldset></dl></div>

    <legend id='NA5tI'><style id='NA5tI'><dir id='NA5tI'><q id='NA5tI'></q></dir></style></legend>
  2. <tfoot id='NA5tI'></tfoot>
    1. <small id='NA5tI'></small><noframes id='NA5tI'>

        <bdo id='NA5tI'></bdo><ul id='NA5tI'></ul>
    2. Laravel 原始 SQL 函数的区别

      时间:2023-09-24
            <bdo id='dXadW'></bdo><ul id='dXadW'></ul>

                <i id='dXadW'><tr id='dXadW'><dt id='dXadW'><q id='dXadW'><span id='dXadW'><b id='dXadW'><form id='dXadW'><ins id='dXadW'></ins><ul id='dXadW'></ul><sub id='dXadW'></sub></form><legend id='dXadW'></legend><bdo id='dXadW'><pre id='dXadW'><center id='dXadW'></center></pre></bdo></b><th id='dXadW'></th></span></q></dt></tr></i><div id='dXadW'><tfoot id='dXadW'></tfoot><dl id='dXadW'><fieldset id='dXadW'></fieldset></dl></div>
              • <legend id='dXadW'><style id='dXadW'><dir id='dXadW'><q id='dXadW'></q></dir></style></legend>
                <tfoot id='dXadW'></tfoot>

                <small id='dXadW'></small><noframes id='dXadW'>

                  <tbody id='dXadW'></tbody>

              • 本文介绍了Laravel 原始 SQL 函数的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                似乎我不是唯一一个在 Laravel 的 DB::raw()、DB::select()、DB::statement() 和 DB::unprepared() 方法之间挣扎的人.似乎几乎需要使用所有 4 个 SQL 语句来尝试一个给定的 SQL 语句,以确定哪个可以工作.任何人都可以澄清它们之间的关系,以及用于什么目的?

                It seems I'm not the only person struggling with the differences between Laravel's DB::raw(), DB::select(), DB::statement(), and DB::unprepared() methods. It seems as if one almost needs to try a given SQL statement with all 4 to identify which will work. Can anybody clarify how they relate to each other, and which to use for what purposes?

                推荐答案

                我会尽量澄清:

                它生成一个原始的和经过清理的 SQL 字符串,传递给其他查询/语句,防止 SQL 注入.是与所有的和永远不会单独使用.并且您永远不应该向您的查询/语句发送未清理的字符串.

                It generates a raw and sanitized SQL string, to be passed to other query/statements, preventing SQL injections. Is to be used with all of the and never alone. And you should never send a not sanitized string to your query/statements.

                DB::select(DB::raw('select * from whatever'));
                

                DB::select()

                用于简单选择:

                DB::select(DB::raw('select * from whatever'));
                

                DB::statement()

                我认为它适用于选择,但应该用于非 SQL 查询命令:

                DB::statement()

                I think it work with selects, but should be used for non SQL query commands:

                DB::statement(DB::raw('update whatever set valid = true;'));
                

                DB::unprepared()

                Laravel 中所有的 SQL 命令都是默认准备好的,但有时你需要在非准备模式下执行命令,因为某些数据库中的某些命令无法在准备模式下运行.这是我打开的一个问题:https://github.com/laravel/framework/issues/53

                DB::unprepared(DB::raw('update whatever set valid = true;'));
                

                这篇关于Laravel 原始 SQL 函数的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Laravel 多对多加载相关模型计数 下一篇:Laravel Eloquent 关系的限制结果

                相关文章

                最新文章

                <i id='5DTvM'><tr id='5DTvM'><dt id='5DTvM'><q id='5DTvM'><span id='5DTvM'><b id='5DTvM'><form id='5DTvM'><ins id='5DTvM'></ins><ul id='5DTvM'></ul><sub id='5DTvM'></sub></form><legend id='5DTvM'></legend><bdo id='5DTvM'><pre id='5DTvM'><center id='5DTvM'></center></pre></bdo></b><th id='5DTvM'></th></span></q></dt></tr></i><div id='5DTvM'><tfoot id='5DTvM'></tfoot><dl id='5DTvM'><fieldset id='5DTvM'></fieldset></dl></div>
                • <bdo id='5DTvM'></bdo><ul id='5DTvM'></ul>

                1. <small id='5DTvM'></small><noframes id='5DTvM'>

                2. <legend id='5DTvM'><style id='5DTvM'><dir id='5DTvM'><q id='5DTvM'></q></dir></style></legend>
                  1. <tfoot id='5DTvM'></tfoot>