Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有准备语句的WHERE子句中的PHP检查字符串_Php_Pdo_Prepared Statement - Fatal编程技术网

带有准备语句的WHERE子句中的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

我正试图用准备好的语句为用户插入一个时间戳。但是,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 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
类型

有关示例,请参见。您必须稍微改变一下指定参数和执行的方式