收到此错误消息:“语法错误,意外'='”

I always get this error message:

syntax error, unexpected '=' in /home/clemjon/Desktop/testListings/26350.ini on line 172

When I check my ini file, there is an "=" on the last line. I don't know how can I remove that.

I'm getting the values on CSV and transfer it on ini. The error is thrown when I parse the ini file I created.

This is how I create the CSV file:

$this->load->helper('csv');
                $this->db->select('*'); 
                $this->db->where('listing_id', $listingId);
                $query = $this->db->get('listing');

            //folder creation
                if (!is_dir('/home/clemjon/Desktop/testListings')) {
                    mkdir('/home/clemjon/Desktop/testListings', 0777, TRUE);
                }

                //file creation
                $file='/home/clemjon/Desktop/testListings/'.$listingId.'.csv';
                if(file_exists($file)){
                    unlink($file);
                }

                $this->load->helper('csv');
                $this->load->dbutil();
                $datas = $this->dbutil->csv_from_result($query);
                $this->load->helper('file');
                if ( ! write_file($file, $datas, 'a+b'))
                {
                    error_log('Unable to write the file');
                }
                else
                {
                    error_log('File written!');
                }

This is how I create the ini file (record from CSV):

$fileName = '/home/clemjon/Desktop/testListings/'.$listingId.'.csv';
            $fp = fopen($fileName, 'r');
            $fields = fgetcsv($fp); 

            $result = array();

            while ($record = fgetcsv($fp))
            {
                $result[] = array_combine($fields, $record);
            }

            $sess_array = array();
            foreach ($result as $row) {
                $sess_array = array(
                    'current_listing_id' => $row['listing_id'],
                    'listing_description' =>$row['description'],
                    'current_listing_min_age' => $row['min_age'],
                    'current_listing_max_age' => $row['max_age'],
                    'current_listing_contact_id' => $row['contact_id']
                );
                $this->session->set_userdata($sess_array);
            }

            $this->write_ini_file($result, '/home/clemjon/Desktop/testListings/'.$listingId.'.ini', true);
            chmod("/home/clemjon/Desktop/testListings/$listingId.ini", 0775);
            $ini_array = parse_ini_file("/home/clemjon/Desktop/testListings/$listingId.ini", false);
            print_r($ini_array);

I think there is a problem when I create the csv which includes extra '=' but I cant figure out what. Any idea? thanks in advance

Thank Junitas! :) I just fetched the result directly from DB (for now)

$this->db->select('*'); 
            $this->db->where('listing_id', $listingId);
            $query = $this->db->get('listing');
            $results = $query->result();

             $file='/home/clemjon/Desktop/testListings/'.$listingId.'.ini';
                if(file_exists($file)){
                    unlink($file);
                }
            $this->write_ini_file($results, $file, true);