подскажите пожалуйста, почему функция $mysqli->query() не выполняется если произвести конкатенацию переменных?
$sql = "
INSERT INTO oc_product
(product_id, model, sku, upc, ean, jan, isbn, mpn, location, quantity, stock_status_id, image, manufacturer_id, shipping, price, points, tax_class_id, date_available, weight, weight_class_id, length, width, height, length_class_id, subtract, minimum, sort_order, status, viewed, date_added, date_modified, dc_label_one, dc_label_two, dc_shortstory)
VALUES
('{$id}', '{$model}', '', '', '', '', '', '', '', '1000', '7', '{$image}', '0', '1', '{$price}', '0', '0', '{$date_available}', '0', '1', '0', '0', '0', '1', '1', '1', '1', '1', '0', '{$date_added}', '{$date_modified}', '', '', '');
";
$sql .= "
INSERT INTO oc_product_description
(product_id, language_id, name, description, tag, meta_title, meta_description, meta_keyword)
VALUES
('{$id}', '2', '{$name}', '{$description}', '', '{$name}', '', '');
";
$mysqli->query($sql);
Сам SQL запрос прекрасно выполняется, в чём проблема?
Никакой конкатенацией заниматься не нужно. Запросы в которых участвуют переменные, должны выполняться с помощью подготовленных выражений.
Поэтому запросы выполняются по отдельности.
$sql = "INSERT INTO oc_product
(product_id, model, sku, upc, ean, jan, isbn, mpn, location, quantity, stock_status_id, image, manufacturer_id, shipping, price, points, tax_class_id, date_available, weight, weight_class_id, length, width, height, length_class_id, subtract, minimum, sort_order, status, viewed, date_added, date_modified, dc_label_one, dc_label_two, dc_shortstory)
VALUES
(?, ?, '', '', '', '', '', '', '', '1000', '7', ?, '0', '1', ?, '0', '0', ?, '0', '1', '0', '0', '0', '1', '1', '1', '1', '1', '0', ?, ?, '', '', '');
";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("sssssss",$id,$model,$image,$price,$date_available,$date_added,$date_modified);
$stmt->execute();
$sql = "INSERT INTO oc_product_description
(product_id, language_id, name, description, tag, meta_title, meta_description, meta_keyword)
VALUES
(?, '2', ?, ?, '', ?, '', '');
";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("ssss",$id,$name,$description,$name);
$stmt->execute();
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости