0

my server has utc +3 hours and I want to correct this. I do not program in php but do the tests with this code!

This is my MYSQL table

CREATE TABLE `sensores_temperatura_1` (
  `fecha` datetime DEFAULT NULL,
  `id` varchar(30) COLLATE utf8mb4_spanish_ci NOT NULL,
  `nombre` varchar(100) COLLATE utf8mb4_spanish_ci NOT NULL,
  `valor` float NOT NULL
)

PHP Code:

<?php
    // Parametros de base de datos
    $mysql_servidor = "localhost";        //localhost
    $mysql_base = "base";     //nombre BD
    $mysql_usuario = "user";   //usuario BD
    $mysql_clave = "pass";        //contraseña BD

    $date = new DateTime();
    $date->setTimeZone(new DateTimeZone("America/Argentina/Buenos_Aires"));
    $get_datetime = $date->format('d.m.Y H:i:s');
    //echo $get_datetime;

    $id = htmlspecialchars($_GET["id"],ENT_QUOTES);
    $temperatura = htmlspecialchars($_GET["temperatura"],ENT_QUOTES);

    // Valida que esten presente todos los parametros
    if (($id!="") and ($temperatura!="")) {

        mysql_connect($mysql_servidor,$mysql_usuario,$mysql_clave) or 
           die("Imposible conectarse al servidor.");
        mysql_select_db($mysql_base) or die("Imposible abrir Base de datos"); 

        $sql = "insert into sensores_temperatura_1 (fecha, id, nombre, valor) 
                values ('$get_datetime','$id','STemp1','$temperatura')";            

        mysql_query($sql);
    }

    ?>
  • 3
    What is your question ? – GMB Feb 24 '19 at 01:37
  • mysql_ ??? I'm surprised your code even runs. – Gordon Linoff Feb 24 '19 at 04:16
  • Possible Duplicate of [how-to-get-current-date-time-in-mysql](https://stackoverflow.com/questions/19246309/how-to-get-current-date-time-in-mysql) – Swati Feb 24 '19 at 04:36
  • If the `server` has the wrong time zone configured, it was a hosting problem. If the database session you are using has a time zone configured you don't want, it's up to you to change it. – greybeard Feb 24 '19 at 06:40
  • @greybeard Thank you for responding and for taking the time to do it! I can not change the hostinger time zone. If you know how to do it, let me know ... thanks! – Rafael Riesgo Feb 24 '19 at 06:47

0 Answers0