File "save_objets_001.php"

Full Path: /home/analogde/www/Chart burndown/save_objets_001.php
File size: 1.26 KB
MIME-type: text/x-php
Charset: utf-8

<?php

/*
CREATE TABLE rows_data (
    id INT AUTO_INCREMENT PRIMARY KEY,
    row_id VARCHAR(255) NOT NULL,
    name VARCHAR(255) NOT NULL,
    select_value VARCHAR(255) NOT NULL,
    count INT NOT NULL,
    cells JSON NOT NULL,
    type ENUM('standard', 'estimation') NOT NULL
);
*/

$servername = "analogdepat.mysql.db";
$dbname = "analogdepat";
$username = "analogdepat";
$password = "Un92pac007";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Get the JSON data from the request body
$data = json_decode(file_get_contents('php://input'), true);

// Prepare the SQL statement
$stmt = $conn->prepare("INSERT INTO rows_data (row_id, name, select_value, count, cells, type) VALUES (?, ?, ?, ?, ?, ?)");

foreach ($data as $rowData) {
    $type = strpos($rowData['id'], 'standard-row-') !== false ? 'standard' : 'estimation';
    $cells = json_encode($rowData['cells']);
    $stmt->bind_param("sssiss", $rowData['id'], $rowData['name'], $rowData['selectValue'], $rowData['count'], $cells, $type);
    $stmt->execute();
}

$stmt->close();
$conn->close();

echo json_encode(["status" => "success"]);
?>