Exemplo n.º 1
0
<?php

/**
 * This is an example code that shows how you can save Handsontable data on server using PHP with PDO (SQLite).
 * This code is not intended to be maximally efficient nor safe. It is for demonstrational purposes only.
 * Changes and more examples in different languages are welcome.
 *
 * Copyright 2012, Marcin Warpechowski
 * Licensed under the MIT license.
 * http://github.com/handsontable/handsontable/
 */
require_once 'functions.php';
try {
    //open the database
    $db = getConnection();
    createCarsTable($db);
    $colMap = array(0 => 'manufacturer', 1 => 'year', 2 => 'price');
    if (isset($_POST['changes']) && $_POST['changes']) {
        foreach ($_POST['changes'] as $change) {
            $rowId = $change[0] + 1;
            $colId = $change[1];
            $newVal = $change[3];
            if (!isset($colMap[$colId])) {
                echo "\n spadam";
                continue;
            }
            $select = $db->prepare('SELECT id FROM cars WHERE id=? LIMIT 1');
            $select->execute(array($rowId));
            if ($row = $select->fetch()) {
                $query = $db->prepare('UPDATE cars SET `' . $colMap[$colId] . '` = :newVal WHERE id = :id');
            } else {
Exemplo n.º 2
0
function resetCarsTable($db)
{
    dropCarsTable($db);
    createCarsTable($db);
    loadDefaultCars($db);
}