Codice PHP:
<?php/*mysqli e pdo library*//*date_default_timezone_set('Europe/Warsaw');$today = new DateTime();$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm$today = date("m.d.y"); // 03.10.01$today = date("j, n, Y"); // 10, 3, 2001$today = date("Ymd"); // 20010310$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month$today = date("H:i:s"); // 17:16:18$today = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (the MySQL DATETIME format)*/
error_reporting(E_ALL);
$USERNAME = "leonardomoretti";$PASSWORD = null;$DBSERVER= "localhost";$DBNAME = "my_leonardomoretti";
if(!($db_connection = new mysqli($DBSERVER, $USERNAME, $PASSWORD, $DBNAME))) die('Connect Error (' . $db_connection->connect_errno . ') '. $db_connection->connect_error);
if(!($db_selection = $db_connection->select_db($DBNAME))) die ("Errore nella selezione del DB.");
$vdata= $_REQUEST['data']; $string = explode(',',$vdata); /*SEPARA IN PARORE LA STRINGA INTERA SEPARATA DAL CARATTERE "," E LE METTE NEL VETTORE */ date_default_timezone_set('Europe/Warsaw'); $date=date ("Y-m-d"); $time=date("H:i:s"); /*$progressive=(int)$string[0];*/ $device=$string[0]; $data1=$string[1]; $data2=$string[2]; /* $query="INSERT INTO MEASUREMENTS (DATA, TIME, DEVICE, DATA1, DATA2) VALUES (?, ?, ?, ?, ?)"; if($stmt = $db_connection->prepare($query)) { $stmt->bind_param("iisss", $date, $time, $device, $data1, $data2); $test = $stmt->bind_param("iisss", $date, $time, $device, $data1, $data2); var_dump($test, $date, $time, $device, $data1, $data2); $result = $stmt->execute(); $stmt->store_result(); echo "%d Row inserite.\n", $db_connection->affected_rows; $stmt->free_result(); if($stmt->more_results()) $stmt->next_result(); */ // Inserisce i dati nella base di dati$query =("INSERT INTO MEASUREMENTS (DATA, TIME, DEVICE, DATA1, DATA2) VALUES (?, ?, ?, ?, ?)"); if (($stmt = $db_connection->prepare($query)) === false) { echo "0 Rows inserite.\n"; die("ERROR: Could not to prepare $query. " . $db_connection->error); } if ($test =$stmt->bind_param("iisss", $date, $time, $device, $data1, $data2) === false) { echo "0 Rows inserite.\n"; die("ERROR: Could not bind params: $date, $time, $device, $data1, $data2. " . $db_connection->error); } var_dump($test, $date, $time, $device, $data1, $data2); if ($stmt->execute() === false) { echo "0 Rows inserite.\n"; die("ERROR: Could not bind execute query. " . $db_connection->error); }echo "1 Row inserite.\n";echo "Records inserted successfully.";$stmt->close(); $db_connection->close();?>