<?php
session_save_path(dirname($_SERVER['DOCUMENT_ROOT']).'/public_html/tmp');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
ini_set('memory_limit', '-1');
set_time_limit('0');
require_once __DIR__ . "/../../vendor/autoload.php";
require_once __DIR__ . "/../../component/Db.php";
$db = Db::connectDB();
$file_url = "/admin/files/prices/prices_1529587320.xlsx";
$what_row = "2";
$col_article = "2";
$col_articleSearch = "0";
$brand = "Volkswagen";
$col_description = "3";
$col_group_price = "5";
$col_price = "4";
$col_min_value = "6";
$col_exchange = "7";
$date = "2018-01-04";
// чистим на пустоту
foreach(['file_url', 'what_row', 'col_article', 'col_articleSearch', 'brand', 'col_description', 'col_group_price', 'col_price', 'col_min_value', 'col_exchange', 'date'] as $field) {
$$field = trim($$field);
}
// переводим в INT
foreach(['what_row', 'col_article', 'col_description', 'col_group_price', 'col_price', 'col_min_value', 'col_exchange'] as $field) {
$$field = (int) $$field;
if($$field === 0) $$field = '';
}
$filePath = realpath(__DIR__ . "/../../" . $file_url);
$row = $what_row;
/*
* Обновляем статус всех прайсов на old
*/
$sql = "UPDATE `dk_prices` SET status = 'old', price = '0' WHERE brand = '$brand'";
$db->query($sql);
$reader = PhpOffice\PhpSpreadsheet\IOFactory::load($filePath);
echo "done";
if(mysqli_num_rows($result) > 0) {
$sql = "UPDATE `dk_prices` SET ?u WHERE searchArticle = ?s and brand = ?s";
$user_data = array(
'description' => $description,
'group_price' => $group_price,
'price' => $price,
'exchange' => $exchange,
'min_value' => $min_value,
'date' => $date,
'status' => 'update'
);
$db->query($sql, $user_data, $searchArticle, $brand);
$db->free($result)
} else {
/*
* Если такого бренда и артикула нету, то добавляем нововую строку
*/
$sql = "INSERT INTO `dk_prices` SET ?u";
$user_data = array(
'article' => $article,
'searchArticle' => $searchArticle,
'brand' => $brand,
'description' => $description,
'group_price' => $group_price,
'price' => $price,
'exchange' => $exchange,
'min_value' => $min_value,
'date' => $date,
'status' => 'new'
);
$db->query($sql, $user_data);
$db->free($result)
не особо умею распоряжаться память на php