2015-04-30 39 views
0

我想在宿主主頁上存儲客戶端的本地時區ut我在我的android Logcat中得到這個錯誤You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7我該怎麼做?我試了date_default_timezone_set在mysql表中存儲客戶端的本地時間

我appreaciate任何幫助。

<?php 
$data = json_decode (file_get_contents ('php://input', true)); 


$mac = $data->{'mac'}; 
$latitude = $data->{'latitude'}; 
$longitude = $data->{'longitude'}; 
$route = $data->{'route'}; 
$created_at = date_default_timezone_set("Europe/Berlin"); 


$con = new mysqli ("domin.com", "username", "password", "ddatabase"); 


// 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, $created_at); 
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

date_default_timezone_set返回bool,而不是日期。您可以使用date而不指定timestamp參數來獲取當前客戶端時間。確保日期的格式與您的表格期望值相匹配。