带有准备语句的WHERE子句中的PHP检查字符串
我正试图用准备好的语句为用户插入一个时间戳。但是,idHash是一个字符串,它从不在正确的行中插入该字符串。当idHash在表中为空时,这些行将受到影响。我如何告诉PHP我希望将其作为字符串处理带有准备语句的WHERE子句中的PHP检查字符串,php,pdo,prepared-statement,Php,Pdo,Prepared Statement,我正试图用准备好的语句为用户插入一个时间戳。但是,idHash是一个字符串,它从不在正确的行中插入该字符串。当idHash在表中为空时,这些行将受到影响。我如何告诉PHP我希望将其作为字符串处理 function setLastRefresh($idHash) { global $dbUser; global $dbPass; // check if the user is in any of the other tables or if sb is trying to
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;
}
可以在绑定参数时指定数据类型。您希望使用
PDO::PARAM_STR
类型
有关示例,请参见。您必须稍微改变一下指定参数和执行的方式