0

Im trying to save the time of a query in my database using the CURRENT_TIMESTAMP. The problem is that the timezone is not correct and when i talked to the people from HostGator support they gave me this answer:

Thomas after researching this issue, I found that you can only change it on the site, to change it on phpmyadmin you would need root access which you do not posses on a shared server.

The server has 2 hours difference from my home country (Chile). Does someone know what can i do? Im using this code to update the database:

<?php

$lat = $_GET['lat'];
$lon = $_GET['lon'];

// Make a MySQL Connection

$db_database = "xxx";
$db_hostname = "xxx";
$db_username = "xxx";
$db_password = "xxx";


$enlace = mysql_connect($db_hostname, $db_username, $db_password);
if (!$enlace) {
    die('No pudo conectarse: ' . mysql_error());
}
echo 'Conectado satisfactoriamente. <br>';
// mysql_close($enlace);


mysql_select_db('xxxxx') or die(mysql_error());


$q = "INSERT INTO `posicion` (`Hora`, `Latitud`, `Longitud`) VALUES 
 (NULL, '$lat','$lon')";

//Run Query
$result = mysql_query($q) or die(mysql_error());

echo "Tamos redi";

?>

And the configuration of the 'Hora' column is:

enter image description here

Does anybody think of a way to solve this?

¡Thanks!

Tomas Campos
  • 67
  • 1
  • 14

1 Answers1

0

In the case of shared hosting you would need to contact support guys or go for a live chat and they can change the default time zone for you.

You can use date_default_timezone_set() which sets a default timezone.

Please give a look here

OR

convert all your times to UTC on server side and just work with UTC instead

Amitesh Kumar
  • 3,051
  • 1
  • 26
  • 42
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26
  • I talked to the guys from support and they told me that i had to change the time in my site :S Can i use something like CURRENT_TIMESTAMP + 2 ? – Tomas Campos Oct 17 '14 at 17:48
  • yes the thing is that you cannot have two TIMESTAMP columns with defaults that reference CURRENT_TIMESTAMP – Avinash Babu Oct 17 '14 at 17:50
  • @AvinashBabu he doesn't have that. He has one column with default CURRENT_TIMESTAMP and the extra ON UPDATE CURRENT_TIMESTAMP. That's not a problem. –  Oct 28 '14 at 14:25