Обновления поля в БД MySql

Есть скрипт который обновляет xls в базу данных MySql. Все происходит на стороне PHP

function import_new_xlsx($path) {
      set_time_limit(0);
      date_default_timezone_set('Asia/Almaty');
      $this->load->helper('string');
      $this->load->helper('date');
     
     $returnMessage = "";
        try {
            include APPPATH . 'third_party/PHPExcel.php';
            include 'SimpleImage.php';
            
            $xlsx = PHPExcel_IOFactory::load($path);
            $xlsx->setActiveSheetIndex(0);
            $sheet = $xlsx->getActiveSheet();
            
            //Соответствие
            /*$mysqlColumn = array(
              'A' => 'title',
              'B' => 'articul',
              'C' => 'barcode',
              'D' => 'usd_price',
              'E' => 'euro_price',
              'F' => 'image',
              'G' => 'discription_pdf',
              'H' => 'price',
              'I' => 'text'
            );*/
            
            $mysqlColumn = array(
              'A' => 'title',
              'B' => 'articul',
              'C' => 'usd_price',
              'D' => 'euro_price',
              'E' => 'visible'
              
            );
            //Поля
            $rowIterator = $sheet->getRowIterator();
            $rowNum = -1;
            foreach($rowIterator as $row) {
                $rowNum++;
                $import_product = array();
                $cellIterator = $row->getCellIterator();
                foreach($cellIterator as $cell) {
                    $cellPath = $cell->getColumn();
                   
                    if(isset($mysqlColumn[$cellPath]) and !empty($cell->getCalculatedValue()))
                        $import_product[$mysqlColumn[$cellPath]] = trim($cell->getCalculatedValue());
                }
                //if (empty($import_product['price'])){
                //    $import_product['price']=0;
               // }
                if(!empty($import_product['usd_price']))
                    $import_product['euro_price']=0;
                    //unset($import_product['euro_price']);
                else
                    //unset($import_product['usd_price']);
                    $import_product['usd_price']=0;
                if((count($import_product) > 0) and (!empty($import_product['articul']))) 
                {
                    if(!empty($import_product['articul']))
                        $this->db->where('articul', $import_product['articul']);
                   // if(!empty($import_product['barcode']))
                    //    $this->db->where('barcode', $import_product['barcode']);
                    //$this->db->where('id_category', $category);
                    //$this->db->where('id_subcategory', $subcategory);

                    $result = $this->db->get('tm_product')->result_array();
                    $product_data = $import_product;
                    
                    if(count($result) > 0) { //обновляем
                        $product_id = $result[0]['id'];
                        $this->db->where('id', $product_id);
                        $this->db->update('tm_product', $product_data);
                        //echo "Найден-$product_id <br/>";
                    } 
                    else 
                    { //добавляем
                        //$this->db->insert('tm_product', $product_data);
                        //$product_id = $this->db->insert_id();
                    }
                }
            }
            //die();
        
        } catch (Exception $e) {
            unlink($path);
            return $e->getLine() .': '. $e->getMessage();
        }
        unlink($path);
        return false;
    }

Все обновляет, все супер, но вот проблема, поле Visible имеет только два значения, 1 или 0. Если в excel 1 то база обновляется нормально, если 0, то он не обновляет.

Не могу понять где тут ошибка?


Ответы (0 шт):