1. <small id='oKxkD'></small><noframes id='oKxkD'>

        <tfoot id='oKxkD'></tfoot>
      2. <legend id='oKxkD'><style id='oKxkD'><dir id='oKxkD'><q id='oKxkD'></q></dir></style></legend>

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

        在 PDO 语句中动态更改列名

        时间:2023-10-05

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

                <tbody id='TzWua'></tbody>
              • <tfoot id='TzWua'></tfoot>

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

                • <bdo id='TzWua'></bdo><ul id='TzWua'></ul>
                • 本文介绍了在 PDO 语句中动态更改列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  是否可以在准备好的 MySQL 语句中将列名作为参数传递?举个例子:

                  Is it possible pass a column name as parameter in a prepared MySQL statement? Take the following example:

                  UPDATE Images
                  SET :placement = :imageURL
                  WHERE ID = :titleID;
                  

                  PDO 在每个参数周围添加 ',所以上面的中间行变成:

                  PDO adds ' around each parameter, so the middle line above becomes:

                  SET 'Homepage' = '1.jpg'
                  

                  MySQL 不喜欢哪个.有没有办法在 PDO 语句中包含字段名称的参数并让它们接受?

                  Which MySQL doesn't like. Is there a way to include parameters for fieldnames in PDO statements and have them accepted?

                  否则我想我将不得不编写几个不同的 PDO 语句,这取决于所选择的内容(?).

                  Otherwise I guess I'll have to write several different PDO statements, depending on what's been chosen(?).

                  推荐答案

                  你需要做这样的事情:

                  $column = 'someColumn';
                  
                  $stmt = $db->prepare("UPDATE tableName SET {$column} = :columnValue WHERE ID = :recordId");
                  

                  参数化占位符仅用于值.

                  Parameterized placeholders are only for values.

                  我建议您阅读@YourCommonSense 就您的问题发表的评论.

                  I would suggest you read the comment @YourCommonSense posted on your question.

                  这篇关于在 PDO 语句中动态更改列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么 PDO 不允许多个同名占位符? 下一篇:如何使用 PDO PHP 创建分页

                  相关文章

                  最新文章

                    <bdo id='py9Z3'></bdo><ul id='py9Z3'></ul>

                  1. <small id='py9Z3'></small><noframes id='py9Z3'>

                  2. <legend id='py9Z3'><style id='py9Z3'><dir id='py9Z3'><q id='py9Z3'></q></dir></style></legend>
                    <tfoot id='py9Z3'></tfoot>

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