I loaded my php script on hosting provider "byethost.com". I am trying to set the time of the records in the created_at to the local time of the client but I am always getting the GTM time. How can I get it to work?
<?php
$data = json_decode ( file_get_contents ( 'php://input', true ) );
$mac = $data->{'mac'};
$latitude = $data->{'latitude'};
$longitude = $data->{'longitude'};
$route = $data->{'route'};
$timeZone = "Europe/Berlin";
$print = date_default_timezone_set($timeZone);
$con = new mysqli ( "domin.com", "username", "password", "database" );
// check whether route's table exist.
$results = $con->query ( "SHOW TABLES like 'bus' " ) or die ( mysqli_error () );
if (($results->num_rows) == 1) {$sql = "REPLACE INTO bus(mac, route, latitude, longitude, created_at)
VALUES( ?, ?, ? , ?, ? )";
$stmt = $con->prepare($sql);
if(false === $stmt){
echo "prepare() failed: ";
}
$rc = $stmt->bind_param("sssss",$mac,$route, $latitude,$longitude, $print);
echo $rc;
if ( false===$rc ) {
echo "bind_param() failed: ";
}
$rc = $stmt->execute();
if ( false===$rc ) {
echo "execute failed.";
}
$stmt->close();
} else {
$create = "CREATE TABLE bus
(id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
mac VARCHAR(30) NOT NULL UNIQUE,
route int(11) ,
latitude FLOAT(10,6) NOT NULL ,
longitude FLOAT(10,6) NOT NULL,
created_at TIMESTAMP NOT NULL" ;
$stmt = $con->prepare($create) or die ( $con->error );
$stmt->execute();
$stmt->close();
}
答案 0 :(得分:1)
也许试试这个?
date_default_timezone_set($timeZone);
时区可以是:
"Europe/Oslo"
有关支持的时区的完整列表,请参阅http://php.net/manual/en/timezones.php