doupingzhi9674 2015-10-08 07:51
浏览 46

PHP fputcsv不会在csv中附加所有数据

I have this simple function to write data to csv, but not able to write all the data that I fetch.

Consider an example where I have 500 records to write to csv, which will correspond to 500 rows in csv. While I run this operation it sometimes write only 120 rows or 150 or even 10 rows . Everytime I run this function I get variable rows not 500 rows.

I have not yet found the root cause of why it not writing all 500 records that I fetch.

Following is the PHP code :

$arrHead = array();
            $arrHead = array('Assign to','Group assigned to','Customer name','Email','Phone','created Date','Ticket type',
                    'Ticket Status','internal note','Ticket number','Subject','Origin','Travel Start Date','Destination',
                    'Package Type','Lead Received','Mail box ID');

$csvfname   =   time().'.csv';



        if(Yii::app()->params['env'] == "LOCAL")
        {
            $basePath = '/var/www/c360/uploads/1/1/';
            $basePath = '/var/www/html/c360/uploads/1/1/'; //  Mangesh
        }
        else
        {
            $basePath = '/data/cview/run/nginx/htdocs/c360/uploads/1/1/';
        }

        $completeFilePath = $basePath . $csvfname;

       if (!empty($arrRecords) && count($aarrRecords) > 0)
        {

            $fp = fopen ($completeFilePath,'w+');
            fputcsv($fp, $arrHead,",",'"');
            chmod($completeFilePath, 0777);

            foreach ($arrRecords as $keyTicket => $arrTicket)
            {
                // preparing columns data into array
                $columnValue = array();
                $columnValue['col1'] =  trim('some value');
                .
                .
                .
                .

                // after the data is prepared in array I write it to CSV
                fputcsv($fp, $columnValue,",",'"');



            }
                fclose ($fp);
        }

After it writes to CSV , and when i check the CSV has less data appended, not all 500 rows

I dont know here I'm wrong in this case.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大