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

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

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

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

      1. php+mysql:在mysql中插入一个php数组

        时间:2023-10-30
        <tfoot id='43h0y'></tfoot>
      2. <small id='43h0y'></small><noframes id='43h0y'>

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

                • 本文介绍了php+mysql:在mysql中插入一个php数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含 30000 多个条目的数组,需要进入 MySQL 表.

                  I have an array with 30000 plus entries that need to go into a MySQL table.

                  最佳做法是什么?从这里?假设数据库中的 [0]、[1] 和 [2] 将是标题"、类型"和客户"

                  What is the best practice? From here? Lets say [0], [1] and [2] in the database would be 'title', 'type' and 'customer'

                  是否添加与表中的列名匹配的键名并调用som魔术"函数?或者手动构建查询...

                  Is it add key names matching the column names in the table and call som "magic" function? Or build the query manually...

                  Array
                  (
                      [0] => Array
                          (
                              [0] => 2140395946
                              [1] => 1SAP
                              [2] => 0041451463
                          )
                  
                      [1] => Array
                          (
                              [0] => 2140411607
                              [1] => 2SAP
                              [2] => 0041411940
                          )
                  
                      [2] => Array
                          (
                              [0] => 2140706194
                              [1] => 4SAP
                              [2] => 0041411943
                          )
                  etc. etc.
                  

                  更新 - 基于答案

                  感谢您的回答.

                  解决方案通常是手动创建 SQL 字符串,并且所有行都可以作为一个插入:

                  The solution would normally be to manually create the SQL-string and all rows can be inserted as one:

                  INSERT INTO `tx_opengate_table` (`machine` ,`customer` ,`type`)
                  VALUES
                    ('m123', 'dfkj45', 'A'),
                    ('m137', 'kfkj49', 'A'), "repeat this line for each entry in the array"
                    ... ... ...
                    ('m654321', '34dgf456', 'C4') "end with out comma, or remove last comma"
                  ;
                  

                  TYPO3专用

                  我碰巧在 CMS TYPO3 中执行此操作,刚刚发现不久前添加的一个新功能:

                  I happen to do this in the CMS TYPO3 and just came across a new function added not that long ago:

                  //Insert new rows
                  $table = 'tx_opengate_stuff';
                  $fields = array('machine','type','customer');
                  $lines = "array as given above"
                  $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows($table,$fields,$lines);
                  

                  推荐答案

                  我会说自己构建它.你可以这样设置:

                  I would say just build it yourself. You can set it up like this:

                  $query = "INSERT INTO x (a,b,c) VALUES ";
                  foreach ($arr as $item) {
                    $query .= "('".$item[0]."','".$item[1]."','".$item[2]."'),";
                  }
                  $query = rtrim($query,",");//remove the extra comma
                  //execute query
                  

                  如果有必要,不要忘记转义引号.

                  Don't forget to escape quotes if it's necessary.

                  另外,请注意不要一次发送太多数据.您可能必须分块执行它,而不是一次全部执行.

                  Also, be careful that there's not too much data being sent at once. You may have to execute it in chunks instead of all at once.

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

                  上一篇:在远程数据库中插入 134675 个值的最快方法 下一篇:PHP 在数据库中插入重复项

                  相关文章

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

                  1. <legend id='goqdN'><style id='goqdN'><dir id='goqdN'><q id='goqdN'></q></dir></style></legend>

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

                      <tfoot id='goqdN'></tfoot>