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

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

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

    1. <tfoot id='Ec3G1'></tfoot>
    2. 在远程数据库中插入 134675 个值的最快方法

      Fastest way to insert 134675 values in remote database(在远程数据库中插入 134675 个值的最快方法)
    3. <tfoot id='11p0f'></tfoot>

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

      <small id='11p0f'></small><noframes id='11p0f'>

        <tbody id='11p0f'></tbody>
        <bdo id='11p0f'></bdo><ul id='11p0f'></ul>

              1. 本文介绍了在远程数据库中插入 134675 个值的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个包含超过 134675+ 个值的数组,我需要将它们插入到我的 mySQL 表中.我知道使用 PHP 和 mySQL 数据插入所需的所有内容.有没有一种快速的方法可以让我在 30-60 秒内将所有这些值插入到远程服务器上?因为当我尝试使用 foreach 方法时,页面超时.远程服务器不允许数据库连接持续超过 60 秒.我不知道为什么.所以请帮助我快速逻辑.

                I have an array with more than 134675+ values, I need to insert them to my mySQL table. I know all the things needed in this to work with PHP and mySQL data insertion. Is there a fast method that would let me insert all these values on a remote server within 30-60 seconds? because when i am trying it with the foreach method, the page is timing out. The remote server is not allowing DB connections to persist for more than 60 seconds. I dont know why. So please help me with a fast logic.

                这是我尝试过的一些代码:

                Here is some code i tried:

                foreach($array as $value)
                {
                    $sql="insert into collected values('".$value."')";
                    $res=mysql_query($sql);
                    //then some extra code.
                }
                

                注意我在服务器上没有这么多的访问权限.我的数据库帐户只能插入值,仅此而已.它是对 mySQL DB 的约束.我不能使用 CSV 或任何其他东西.

                NOTE I dont have so many access privileges on the server. My DB account can only insert values and nothing more than that. And its a constraint on the mySQL DB. I cannot use CSV or any other thing.

                推荐答案

                您可以在循环中包含 mysql_ping() 函数.此函数检查以确保连接已打开,如果未打开,则重新连接.

                You could include in your loop the mysql_ping() function. This function checks to make sure that the connection is open, and if it is not, it re-connects.

                使用您自己的示例,您可以执行以下操作:

                Using your own example, you could do something like:

                foreach($array as $value) {
                    mysql_ping($dbconn);
                    $sql="insert into collected values('".$value."')";
                    $res=mysql_query($sql);
                    //then some extra code.
                }
                

                编辑:需要注意的是,根据文档,在 MySQL 5.0.14 之后,PHP 不会自动重新连接.如果您使用较新版本的 MySQL,则必须放入自己的连接逻辑,可能是这样的(我没有测试过):

                Edit: It should be noted that according to the docs, after MySQL 5.0.14, PHP does not automatically reconnect. If you use a newer version of MySQL you will have to put in your own connection logic, maybe like this (I haven't tested):

                function check_dbconn($connection) {
                    if (!mysql_ping($connection)) {
                        mysql_close($connection);
                        $connection = mysql_connect('server', 'username', 'password');
                        mysql_select_db('db',$connection);
                    } 
                    return $connection;
                }
                
                foreach($array as $value) {
                    $dbconn = check_dbconn($dbconn);
                    $sql="insert into collected values('".$value."')";
                    $res=mysql_query($sql, $dbconn);
                    //then some extra code.
                }
                

                这篇关于在远程数据库中插入 134675 个值的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                <tfoot id='0Ckmg'></tfoot>

                <small id='0Ckmg'></small><noframes id='0Ckmg'>

                  <legend id='0Ckmg'><style id='0Ckmg'><dir id='0Ckmg'><q id='0Ckmg'></q></dir></style></legend>

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

                          <bdo id='0Ckmg'></bdo><ul id='0Ckmg'></ul>