Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 高效的MySQL插入_Php_Mysql - Fatal编程技术网

Php 高效的MySQL插入

Php 高效的MySQL插入,php,mysql,Php,Mysql,我有一个PHP脚本,正在将值插入MySQL表中。这在处理几千行数据时工作得很好,但随着我增加数据量,只有一部分数据插入到MySQL表中 它似乎只在大约6000行数据之后停止。真的,我希望它能为40000行工作,之后它需要160000行。 我必须运行脚本几次才能将更多数据添加到表中 我对使用SQL语句还不熟悉,我认为我设置SQL语句的方式效率不高 我的一些代码: for($x=0;$x<count($array_athlete); $x++){ $checkuser=m

我有一个PHP脚本,正在将值插入MySQL表中。这在处理几千行数据时工作得很好,但随着我增加数据量,只有一部分数据插入到MySQL表中

它似乎只在大约6000行数据之后停止。真的,我希望它能为40000行工作,之后它需要160000行。 我必须运行脚本几次才能将更多数据添加到表中

我对使用SQL语句还不熟悉,我认为我设置SQL语句的方式效率不高

我的一些代码:

for($x=0;$x<count($array_athlete); $x++){

          $checkuser=mysqli_query($link,"SELECT * FROM `Events_testing2` WHERE `location`='$location'
          AND `barcode`='$array_barcode[$x]' AND `date`='$date'");
          $rowcount=mysqli_num_rows($checkuser); //checks if barcode exists for that user in that location on that date.  Inserts data if doesn't already exist.

          if($rowcount>0){
                          }
          else{
               $queryInsertUser=mysqli_query($link, "INSERT INTO `Events_testing2` (`eventID`,`location`,`date`,`barcode`,`athlete`,`time`,`Run Points`,`Volunteer Points`,`Gender`,`Gender pos`) 
               VALUES (' ','$location','$date','$array_barcode[$x]','$array_athlete[$x]','$array_time[$x]','$array_score[$x]',' ','$array_gender[$x]','$array_gender_pos[$x]') ");

              }
   }

for($x=0;$x按块插入,就像先插入1000(1-1000),然后再插入下一个1000(1001-2000)。这样,您就不会遇到错误。

尝试预先设置php的时间限制

<?php
ini_set('max_execution_time', '0'); // infinite
set_time_limit(0); // infinite

/// do your stuff

使用终端运行此脚本1:
插入xyz(a,b,c)值(1,2,3)、(1,4,5)、(5,6,7)、(5,6,7)
您可以一次插入多个值集。插入多少取决于mysql配置和php内存限制问:
它似乎停止了,并且在任何地方都没有错误消息?Tip2:
Gender pos
不要创建表名和空格,使用下划线!谢谢@justonundermillion我将尝试使用Tip1设置我的代码。我喜欢一次插入多个值集合的想法。要设置值(1,2,3)(等),我可以使用循环吗?你可以在插入之间拆分为循环{values}错误消息:有时会得到网关超时错误提示2:谢谢