Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.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 INSERT语句失败_Php_Mysql_Oop_Pdo - Fatal编程技术网

Php 发布大型数组时Mysql INSERT语句失败

Php 发布大型数组时Mysql INSERT语句失败,php,mysql,oop,pdo,Php,Mysql,Oop,Pdo,我已经在网上搜索了好几天了,我的头发都被拔出来了。它在我的XAMPP localhost上运行良好,在我的在线测试服务器上运行良好,直到我更新了PHP版本,并且由于不推荐使用的语法而不得不重写代码 基本上,我正在为摄影客户制作一个后端数据库。其中一个表用于存储图像信息。我没有尝试存储某种类型的实际图像块,我只是想存储什么以及存储在哪里 似乎正在发生的事情是,如果我尝试输入一个包含数百幅图像的快照目录的内容,当我点击输入屏幕时,屏幕会发生变化,而不是告诉我输入了多少,而是转到一个418未使用的页面

我已经在网上搜索了好几天了,我的头发都被拔出来了。它在我的XAMPP localhost上运行良好,在我的在线测试服务器上运行良好,直到我更新了PHP版本,并且由于不推荐使用的语法而不得不重写代码

基本上,我正在为摄影客户制作一个后端数据库。其中一个表用于存储图像信息。我没有尝试存储某种类型的实际图像块,我只是想存储什么以及存储在哪里

似乎正在发生的事情是,如果我尝试输入一个包含数百幅图像的快照目录的内容,当我点击输入屏幕时,屏幕会发生变化,而不是告诉我输入了多少,而是转到一个418未使用的页面,说

服务器遇到内部错误或配置错误,无法完成您的请求

我一直在努力缩小要增加的缓冲区或变量的范围,比如max_allowed_packet、max_input_vars。。。还是不走运。我甚至试着比较两台服务器之间的phpinfo,以找出其中一台工作而另一台不工作的原因

这是我正在做的。。。列表页

<?php
// set page headers
$page_title = "Enter Images into Database";
include_once 'auth.php';

// get database connection
include_once 'config/fpaddb.php';
include_once 'objects/clients.php';
include_once 'objects/photoshoots.php';
include_once 'objects/images.php';

$database = new Database();
$db = $database->getConnection();

$colname_chk_Images = "-1";
if (isset($_GET['ShootId'])) {
  $colname_chk_Images = $_GET['ShootId'];
}
$colname1_chk_Images = "NULL";
if (isset($_GET['ShootFolder'])) {
  $colname1_chk_Images = $_GET['ShootFolder'];
}

$colname_get_Images = "-1";
if (isset($_SESSION['cID'])) {
  $colname_get_Images = $_SESSION['cID'];
}
$entered=0; //check for already entered images

?>
<?php
$dirname=$_SESSION['cIFolder'];
$Clogin=$_SESSION['Clogin'];
$ClientID=$_SESSION['cID'];
$_SESSION['CURR_CLIENT_ID'] = $ClientID;
$maindir=$_GET['ShootFolder'];
$ShootId=$_GET['ShootId'];
$dir=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."protect/clientfolders/".$Clogin."/users/".$Clogin."/images/".$maindir;
$_SESSION['dir']=$dir;
$dir2="/protect/clientfolders/".$Clogin."/users/".$Clogin."/images/".$maindir;
$dirt= "/phpThumb-master/";
$dirn= dirname($_SERVER['PHP_SELF']);
$filesArray=array_map('basename', glob($dir."/*.jpg"));
$lightbox_data= "FPAD_Lightbox";
$thumb =    "$dir2/";
$notThumb =   "$dir2/";
$ic = count($filesArray);
$_SESSION['SESS_TOTNUM'] = $ic;
$_SESSION['sID'] = $ShootId;
$sID = $_SESSION['sID'];

include_once 'header_a.php';
?>
<div class="container">
<?php
echo $_SESSION['SESS_TOTNUM']." images found ";
echo "for Shoot ID#: ".$_SESSION['sID']."<br>";
echo "*Note* - if input boxes come up GREEN, then images are already loaded into the database";
?>
<p>
<?php

$images1 = new Image($db);

$images1->ShootId = $colname_chk_Images;
$images1->directory = $colname1_chk_Images;
$images1->ClientID = $colname_get_Images;
$chk_Images = $images1->checkImages();
$get_Images = $images1->getImages();

$Images = array();

while ($row_get_Images = $get_Images->fetch(PDO::FETCH_ASSOC))
    {
        $Images[] = $row_get_Images['image_name'];
    }
?></p>
<form method="POST" name="form1" id="form1" action="input.php">
    <table id="clientshoots" class="table table-condensed table-bordered table-small">
  <tr>
    <th>image_id</th>
    <th>image_name</th>
    <th>image_path</th>
    <th>image_path_root</th>
    <th>image_size</th>
    <th>directory</th>
    <th width="auto">ShootId</th>
    <th width="auto">ClientID</th>
    <th>ClientName</th>
    <th>login</th>
  </tr>
  <?php $ic=0;
   for($i=0;$i<count($filesArray);$i++) { 
        $fileinfo = $filesArray[$i];
        $fname=$dir."/".$fileinfo;
        $fname2=$dir2."/".$fileinfo;
        $size = filesize($fname);
        $atime = date("F d, Y H:i:s", fileatime($fname));
        $mtime= date("F d, Y H:i:s", filemtime($fname));
        $perms=decoct(fileperms($fname) & 0777);
        $type=filetype($fname);
        $pth=realpath($fname);
        $name=basename($fname);
        $dn=dirname($fname2);
        if (in_array($fileinfo, $Images)) {
        $entered=1;    
        echo "<style type=\"text/css\">\n";
        echo "input {\n";
        echo "background-color:#00FF33;\n";
        echo "}\n";
        echo "</style>";
        } 
    ?>
    <tr>
    <td>&nbsp;</td>
      <td><input type="text" name="image_name[]" value="<?php echo $fileinfo; ?>" readonly/></td>
      <td><input type="text" name="image_path[]" value="<?php echo $dir; ?>" readonly/></td>
      <td><input type="text" name="image_path_root[]" value="<?php echo $dir2; ?>" readonly/></td>
      <td><input type="number" name="image_size[]" value="<?php echo $size; ?>" readonly/></td>
      <td><input type="text" name="directory[]" value="<?php echo $maindir; ?>" readonly/></td>
      <td><input type="number" name="ShootId[]" value="<?php echo $ShootId; ?>" readonly/></td>
      <td><input type="number" name="ClientID[]" value="<?php echo $ClientID; ?>" readonly/></td>
      <td><input type="text" name="ClientName[]" value="<?php echo $_SESSION['cName']; ?>" readonly/></td>
      <td><input type="text" name="login[]" value="<?php echo $Clogin; ?>" readonly/></td>
    </tr>
    <?php next($filesArray);
    $ic=$ic+1;
    } 

    $_SESSION['SESS_IC'] = $ic;?>
</table>
<?php if ($entered == 1){
  echo  "<a href=\"viewClient.php?ClientID=".$ClientID."\" class=\"btn btn-primary active\">Return</a>";
} else { 
  echo  "<input class=\"btn-primary\" style=\"background-color:\" id=\"Insert records\" type=\"submit\" value=\"Insert records\">";
}?>
<input type="hidden" name="MM_insert" value="form1">
<input type="hidden" name="sID" value="<?php echo $sID; ?>">
</form>
</div>
<br>
  <!-- /container -->
 <?php include 'footer_b.php'; ?>
然后是input.php页面

<?php
// set page headers
$page_title = "Enter Images into Database";
include_once 'auth.php';

// get database connection
include_once 'config/fpaddb.php';
include_once 'objects/clients.php';
include_once 'objects/photoshoots.php';
include_once 'objects/images.php';
include_once 'objects/ratings.php';

$database = new Database();
$db = $database->getConnection();

$sID = $_SESSION['sID'];
$ic = $_SESSION['SESS_IC'];
$ma = $_SESSION['SESS_CLIENT_MULTI'];
$gn = $_SESSION['SESS_CLIENT_GRPNO'];
$cID = $_SESSION['cID'];

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

    //Function to sanitize values received from the form. Prevents SQL injection

        function clean($str) {
        $str = filter_var(($str), FILTER_SANITIZE_STRING);
        return ($str);
    }

$image1 = new Image($db);   

$count = count($_POST['image_name']);
$fileinfo = clean($_POST['image_name']);

    //Check for duplicates
    if($fileinfo != '') {
            for($i=0;$i<$count;$i++) { 
            $fileinfo = clean($_POST['image_name'][$i]);
            //echo $fileinfo;
            $image1->image_name = $fileinfo;
            $result = $image1->check4Dup(); 
            if($result) {
                if(count($result) > 0) {
                    $errmsg_arr[] = 'Image already entered into Database';
                    $errflag = true;
                }
                $result = NULL;
            }
            else {
                die($e->getMessage());
            }
            next($count);   
            }
        }
$image1->ic = $ic;
$num = $image1->create();   

$colname_newImages = "-1";
if (isset($sID)) {
  $colname_newImages = $sID;
}
$image1->ShootId = $sID;
$newImages = $image1->countOneShoot();
$row_newImages = $newImages->fetch(PDO::FETCH_ASSOC);
$totalRows_newImages = $newImages->rowCount();
$ic2 = $totalRows_newImages;
$_SESSION['SESS_TOTNUM_ENT'] = $ic2;
header("Location: rs_images.php"); 


include_once 'header_a.php';
?>
<div class="container">
<?php 
echo "Success! Number of images entered is ".$ic2; ?>
<br><br>
<p><input name="Verify" type="button" value="Verify Inputs" onclick="MM_goToURL('parent','rs_images.php');return document.MM_returnValue"/></p>
</div>
 <?php include 'footer_b.php'; ?>
和类文件

<?php

class Image{

        // database connection and table name
    private $dbh;
    private $table_name = "images";

    // object properties
    public $image_id;
    public $image_name;
    public $image_path;
    public $image_path_root;
    public $image_size;
    public $directory;
    public $ShootId;
    public $ClientID;
    public $ClientName;
    public $login;
    public $ic;

    public function __construct($db){
        $this->dbh = $db;
    }

    // Clean Function
    function clean($str){
        $str = filter_var(($str), FILTER_SANITIZE_STRING);
        return ($str);
    }

    // test function
    function test(){

        $ic = $this->ic;

        $i=1;
        $j=1;
        foreach ($_POST['image_name'] as $row=>$iname)
        {
            $image_name = clean($iname);
            $image_path = clean($_POST['image_path'][$row]);
            $image_path_root = clean($_POST['image_path_root'][$row]);
            $image_size = clean($_POST['image_size'][$row]);
            $directory = clean($_POST['directory'][$row]);
            $ShootId = clean($_POST['ShootId'][$row]);
            $ClientID = clean($_POST['ClientID'][$row]);
            $ClientName = clean($_POST['ClientName'][$row]);
            $login = clean($_POST['login'][$row]);
            $Clogin = $login."');";

            $i=$i+1;
            $j=$j+1;

            $qry1st = "INSERT INTO `images` (image_name, image_path, image_path_root, image_size, directory, ShootId, ClientID, ClientName, login) VALUES ";
            $sql_array = "('".$image_name."', '".$image_path."', '".$image_path_root."', ".$image_size.", '".$directory."', ".$ShootId.", ".$ClientID.", '".$ClientName."', '".$Clogin;
            //$stmt = $this->dbh->prepare($qry1st.$sql_array);
            //$stmt->execute();
            echo $qry1st.$sql_array;
        }

    }

     // create function
    function create(){

        $ic = $this->ic;
        $qry1st = "INSERT INTO `images` (image_name, image_path, image_path_root, image_size, directory, ShootId, ClientID, ClientName, login) VALUES ";

        $sql_array = array(); // This is where we'll queue up the rows

        $queue_num = 50; // How many rows should be queued at once?
        $i=1;       
        foreach ($_POST['image_name'] as $row=>$iname)
        {
        $image_name = clean($iname);
        $image_path = clean($_POST['image_path'][$row]);
        $image_path_root = clean($_POST['image_path_root'][$row]);
        $image_size = clean($_POST['image_size'][$row]);
        $directory = clean($_POST['directory'][$row]);
        $ShootId = clean($_POST['ShootId'][$row]);
        $ClientID = clean($_POST['ClientID'][$row]);
        $ClientName = clean($_POST['ClientName'][$row]);
        $login = clean($_POST['login'][$row]);
        if ($i==($_SESSION['SESS_TOTNUM'])) {
        $login_term = $login."');";
        }
        else
        {
        $login_term = $login."')";
        $i=$i+1;
        }

        $sql_array[] = "('".$image_name."', '".$image_path."', '".$image_path_root."', ".$image_size.", '".$directory."', ".$ShootId.", ".$ClientID.", '".$ClientName."', '".$login_term;

        // Add a new entry to the queue
        $c=0;
        if (count($sql_array) >= $queue_num)
        { // Reached the queue limit

        $addImages = $this->dbh->query($qry1st . implode(', ', $sql_array)); // Insert those that are queued up
        $addImages->execute();

        $sql_array = array(); // Erase the queue
        }//End if 

        }//end foreach

        if (count($sql_array) > 0) // There are rows left over
        {
        $addImages = $this->dbh->query($qry1st . implode(', ', $sql_array));
        $addImages->execute();
        }
    }

    function checkImages(){

    $query_chk_Images = "SELECT images.image_name FROM images WHERE ShootId = ? AND directory = ?";

    $chk_Images = $this->dbh->prepare ($query_chk_Images);
    $chk_Images->bindValue(1, $this->ShootId);
    $chk_Images->bindValue(2, $this->directory);
    $chk_Images->execute();
    return $chk_Images;
    }

    // create function
    function getImages(){

    $query_get_Images = "SELECT * FROM images WHERE ClientID = ? ORDER BY image_name ASC";

    $get_Images = $this->dbh->prepare ($query_get_Images);
    $get_Images->bindValue(1, $this->ClientID);
    $get_Images->execute();
    return $get_Images;

    }

     // create function
    function getImageID(){

        $query_rsImageID = "SELECT * FROM images WHERE ShootId = ? ORDER BY image_id ASC";

        $rsImageID = $this->dbh->prepare($query_rsImageID);
        $rsImageID->bindValue(1, $this->ShootId);
        $rsImageID->execute();

        return $rsImageID;
    }

     // create function
    function get_image_id(){

        $q = "SELECT image_id FROM images WHERE ShootId = ? ORDER BY image_id ASC";

        $stmt = $this->dbh->prepare($q);
        $stmt->bindValue(1, $this->ShootId);
        $stmt->execute();

        return $stmt;
    }

    // create function
    function countOneShoot(){

        $query_newImages = "SELECT * FROM images WHERE ShootId = ?";

        $newImages = $this->dbh->prepare($query_newImages);
        $newImages->bindValue(1, $this->ShootId);
        $newImages->execute();

        return $newImages;
    }

    // create function
    function check4Dup(){

        $qry = "SELECT * FROM `images` WHERE image_name = ?";

        $result = $this->dbh->prepare($qry);
        $result->bindValue(1, $this->image_name);
        $result->execute();

        return $result;
    }
}
我已经去掉了所有我尝试过的额外内容,比如一次输入一条记录,用冒号前缀的字段名而不是?'绑定值。我试过不同的循环。我认为这可以归结为试图通过一个查询推得太多。。。但是为什么它可以在XAMPP上工作,为什么它可以在PHP5.2上工作


我很感激你能告诉我这件事。这是我第一篇关于PHP、MySQL或任何与网站相关的文章,我一直在学习这些东西,并将其90%完成并调试,当我把它放到网上,对实际目录和客户端文件夹进行真正的测试时,我发现在PHP5.4和5.2之间,有很多变化,我发现自己几乎重写了每一行,以升级到MySQLi或PDO/OOP。在互联网上进行了大量搜索后,我选择了面向对象的方法,仍然需要重写上面的更多代码来清理大量内容,但现在我正在排除插入失败的故障,我自己或在所有论坛的帮助下都无法解决,我到目前为止读过的文章和博客。

这可能是部署在服务器上设置的最大文章大小。您知道服务器是如何配置的吗?有很大的不同吗?根据phpinfo,它的post_max_size=65MI在我上面的类文件中也注意到,查询代码增加了一倍$addImages=$this->dbh->query$qry1st。内爆“,”,$sql_数组$添加图像->执行;我只需要其中一个,而不是两个。。。所以我把第一个改为“从查询中准备”。所以这不是问题所在。。。我可以得到的代码与16个图像目录工作。。。但是一个超过100的挂起一秒钟,然后触发418。