超过100行未使用php-throught形式插入postgresql


more then 100 rows not inserting in postgresql using php throught form

我试图在一个循环中使用PHP将100多行插入postgresql数据库。我没有犯任何错误。

当我尝试添加大约50到60条记录时,数据被插入。但当记录在100左右及以上时,它不会被插入。

下面是我尝试过的代码。请通过并帮助我解决这个问题。

提前谢谢。

<?php
     $userid = $_SESSION['user_id'];
       $array ='';
       $resultAgain ='';
    if (isset($_POST['save'])) {
      // $sponsorship_id = $_POST['sponsorid'];
      $resultAgain=array();
      $resultAgain = $_SESSION['arr_rows']; 
   for ($i = 0; $i <count($resultAgain); ++$i) {
  $recieptid = $resultAgain[$i]['recieptid'];
  $childid = $resultAgain[$i]['childid'];
  $openingbalance_fee = $resultAgain[$i]['openingbalance_fee']; 
  $openingbalance_familyhelp = $resultAgain[$i]['openingbalance_familyhelp']; 
  $mayreciept = $resultAgain[$i]['mayreciept'];
  $december_reciept = $_POST['decreciept'.$resultAgain[$i]['presentclass']];
  $adminfees = $_POST['adminfees'.$resultAgain[$i]['presentclass']];
  $schoolfee = $_POST['schoolfee'.$resultAgain[$i]['presentclass']];
  $familyhelp = $resultAgain[$i]['family_help'];
  $year = $_POST['yearName']; 
  $submit = $_POST['save'];
        // call insert function 
          $sql1="SELECT fn_reciept_insert($childid,
                                        '$openingbalance_fee', 
                                        '$openingbalance_familyhelp', 
                                        '$mayreciept', 
                                        '$december_reciept', 
                                        '$adminfees',
                                        '$familyhelp',
                                        '$schoolfee',
                                        '$year',
                                         $userid,
                                         localtimestamp,
                                         $userid,
                                         localtimestamp)";
          $result1 = pg_query($dbconn,$sql1);
        if (!$result1) { 
    echo '<script>alertMX("Data Not Updated")</script>';
   }
else
   {
    echo '<script>alertMX("Data inserted Successfully")</script>';
   } }
    }
 }
 ?>

首先,确保在脚本结束时关闭数据库连接。如果你一直有问题,试着增加你的max_connectionshttps://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server#max_connections

ALTER SYSTEM SET max_connections TO 300;

并重新启动postgresql服务器。

此外,问题可能不在于您尝试INSERT的数据量。您正在使用未映射的数据创建查询。这意味着什么?如果您放入该大查询字符串中的某个变量具有'字符,则查询字符串将出错,这是一个很大的安全问题(请阅读sql注入)。数据量越大,出现'的机会就越大。您应该逃离您的数据