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

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

        <legend id='Jxc3I'><style id='Jxc3I'><dir id='Jxc3I'><q id='Jxc3I'></q></dir></style></legend>

        创建一个动态的php插入到mysql函数中?

        时间:2023-10-30
        • <bdo id='StpT8'></bdo><ul id='StpT8'></ul>
            • <small id='StpT8'></small><noframes id='StpT8'>

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

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

                    <tbody id='StpT8'></tbody>
                  <tfoot id='StpT8'></tfoot>
                  本文介绍了创建一个动态的php插入到mysql函数中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含很多变量的帖子,我想知道是否有某种方法可以动态地将信息插入 mysql,而不是手动输入,因为帖子变量会根据用户选择的内容而变化.

                  i have a post with a LOT of variables, and I was wondering if there was some way of inserting the information into mysql dynamically, rather than typing it all out manually, as the post variables change depending on what the user selects.

                  推荐答案

                  这就是我们用来做类似事情的方法(插入到我们无法控制的表中,并且没有 API 访问权限)

                  This is what we use to do a similar thing (inserting into a table we have no control over, and which has no API access)

                  使用 DESCRIBE 查询可确保仅插入存在的列.

                  Using the DESCRIBE query ensures only columns that exist are inserted.

                  $db = new DB();
                  $sql = 'DESCRIBE `table`';
                  $result = $db->query($sql);
                  $row = array();
                  $query = array();
                  
                  while ($row = $result->fetchRow())
                  {
                      if (array_key_exists($row['field'], $form_data))
                          if (is_null($form_data[$row['field']]))
                              $query[$row['field']] = 'NULL';
                          else
                              $query[$row['field']] = $db->quote($form_data[$row['field']]);
                  }
                  
                  $keys = array_keys($query);
                  
                  foreach ($keys as &$key)
                      $key = $db->quoteIdentifier($key);
                  
                  unset($key);
                  
                  $vals = array_values($query);
                  
                  $sql = 'INSERT INTO `table` '
                       . '(' . implode(', ', $keys) . ') '
                       . 'VALUES(' . implode(', ', $vals) . ')';
                  

                  DB() 是我们围绕 MDB2 的包装器.

                  edit: DB() is our wrapper around MDB2.

                  当然,这允许他们填写整行.如果您有受限制的列(自动增量 ID 等),则必须从表单数据中过滤掉这些列...

                  And of course this allows them to fill in the entire row. If you have restricted columns (auto-increment ids and such), you'll have to filter those out of the form data...

                  这篇关于创建一个动态的php插入到mysql函数中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 mySQL 通过 PHP 向 INSERT 添加日期和时间戳? 下一篇:PHP ColdFusion9 AES 加密 - 不同的结果

                  相关文章

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

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

                    <legend id='nYhIB'><style id='nYhIB'><dir id='nYhIB'><q id='nYhIB'></q></dir></style></legend>
                      <bdo id='nYhIB'></bdo><ul id='nYhIB'></ul>