使用关联数组键时,不需要的字符插入到PDO预处理语句中

时间:2012-08-05 21:32:35

标签: sql insert pdo

我创建了一个使用关联数组键的PDO语句但是当执行SQL时会添加“\”和“'”,我该如何防止这种情况?

这是查询

public function queryUpdateClasses($classesToUpdate,$packageId){
        $sql = "SELECT class.ClassId FROM class JOIN package ON package.PackageId = class.PackageId WHERE class.ClassName = ? AND package.PackageId = ?";
        $query = $this->_conn->prepare($sql);
        foreach($classesToUpdate as $updateKey=>$updateValue){
            echo $updateKey;
            $query->execute(array($updateKey,$packageId));
        }
    }

以下是日志文件的输出

98 Query    SELECT class.ClassId FROM class JOIN package ON package.PackageId = class.PackageId WHERE class.ClassName = '\'LogActivityTable\'' AND package.PackageId = '69'

$updateKey;被回显时,它只显示'LogActivityTable'。

0 个答案:

没有答案