2011-05-09 81 views
1

我正在嘗試爲預準備語句的用戶插入時間戳。但是,idHash是一個字符串,它永遠不會將該字符串插入到正確的行中。當表中idHash爲空時,這些行會受到影響。我怎麼能告訴PHP,我希望這被視爲一個字符串?PHP使用預處理語句在WHERE子句中檢查字符串

function setLastRefresh($idHash) 
{ 
    global $dbUser; 
    global $dbPass; 

    // check if the user is in any of the other tables or if sb is trying to hack the db 

    $db = new PDO('mysql:host=localhost;dbname=myDB', $dbUser, $dbPass); 
    $preparedStatement = $db->prepare("update users set lastRefresh = NOW() WHERE idHash=:idHash"); 
    $preparedStatement->execute(array(':idHash' => $idHash)); 
    $preparedStatement->closeCursor(); 
    return 0; 
} 

回答

0

您可以在綁定參數時指定數據類型。你想使用PDO::PARAM_STR類型。

查看http://www.php.net/manual/en/pdostatement.bindparam.php舉例。你將不得不改變你如何指定參數和執行一點點。

+0

謝謝喬,做到了這一點,現在它工作正常。 – 2011-05-09 16:07:03