0

我创建了一个使用关联数组键的 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”。

4

0 回答 0