Buonasera,
ricapitolando ho aggiunto queste righe:
Codice PHP:
$result = $db_connection->query("SELECT COUNT(*) FROM MEASUREMENTS");
if($result) {echo $db_connection->insert_id . '<br />';}
else {echo "Errore query: " . $db_connection->error;}
al posto di queste:
Codice PHP:
$result = $db_connection->query("SELECT COUNT(*) FROM MEASUREMENTS");
if (count($result) > 0) {
while($row=$result->fetch_array(MYSQLI_ASSOC)){
echo $row['blah'] . '<br />';
{
}
else { echo "<p>Nothing matched your query.</p>"; }
adesso non ho errori ma il numero di righe che mi scrive 0 (zero) invece di 3.
Ho pulito il codice per renderlo più leggibile ed è il seguente:
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[1];
$data1=(float)$string[2];
$data2=(float)$string[3];
$result = $db_connection->query("SELECT COUNT(*) FROM MEASUREMENTS");
if($result) {echo $db_connection->insert_id . '<br />';}
else {echo "Errore query: " . $db_connection->error;}
$query=("INSERT INTO MEASUREMENTS (ID,DATA, TIME, DEVICE, DATA1, DATA2) VALUES ( '$progressive','$date', '$time', '$device', '$data1', '$data2')");
if(mysqli_query($db_connection, $query)){
echo "Records inserted successfully.";
} else{
echo "ERROR: Could not able to execute $query. " . mysqli_error($db_connection);
}
$db_connection->close();
?>