2014-01-08 29 views
1

我開始與MySQL準備語句,我不能提前,由於我不明白的錯誤。這裏是我的功能來更新數據庫德:php mysql準備語句問題

public function updateUserData($user_label,$user_alliance, $score, $rank, $timestamp, $user_id, $db_object){ 


    $sql='UPDATE users SET label = ?, alliance = ?, points = ?, position = ?, modified = ?, WHERE user_id = ?'; 

    $label = $user_label; 
    $alliance = $user_alliance; 
    $points = $score; 
    $position = $rank; 
    $modified = $timestamp; 
    $user_id_q = $user_id; 

    $stmt = $db_object->prepare($sql); 
    if($stmt === false) { 
     trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $db_object->error, E_USER_ERROR); 
    } 

    $stmt->bind_param('ssiiii',$label,$alliance,$points,$position,$modified,$user_id_q); 

    /* Execute statement */ 
    $stmt->execute(); 

    echo $stmt->affected_rows; 

    $stmt->close(); 

} 

下面是我如何使用它:

//Get user Data 
$user = new user(); 
$page_clasif = $user->getPagClasif($ch,$url_clasif); 
$user_label = $user->findPlayerName($page_clasif); 
$user_alliance = $user->findAllianceName($page_clasif); 
$rank = $user->findRank($page_clasif); 
$score = $user->findScore($page_clasif); 
$user_id = $user->findPlayerId($page_clasif); 
$version = $user->findVersion($page_clasif); 
$user_universe = $user->findUniverse($page_clasif); 

//Get install date as timestamp 
$core = new core(); 
$timestamp = $core->dateAsTimestamp(); 
//Update User 
$user->updateUserData($user_label,$user_alliance,$score,$rank,$timestamp,$user_id,$conn); 

這裏的錯誤:

PHP Fatal error: Wrong SQL: UPDATE users SET label = ?, alliance = ?, points = ?, position = ?, modified = ?, WHERE user_id = ? Error: 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 'WHERE user_id = ?' 

任何想法? 在此先感謝。

+1

你有太多的','秒。 –

回答

3

你有WHERE關鍵字前一個多餘的逗號:

$sql='UPDATE users SET label = ?, alliance = ?, points = ?, position = ?, modified = ?, WHERE user_id = ?'; 
//                 remove this comma --^ 
+0

非常感謝,菜鳥的錯誤。 ):對我感到羞恥。 – sms