【问题标题】:Equivalent mysql_real_escape_string in cakephp [closed]cakephp中等效的mysql_real_escape_string [关闭]
【发布时间】:2013-02-26 10:31:38
【问题描述】:

我想上传一个带有 blob 字段的文件 我使用蛋糕框架 但我不能使用 mysql_real_escape_string 函数 请帮帮我!

【问题讨论】:

标签: php cakephp cakephp-1.3 cakephp-2.1


【解决方案1】:

如果你打算用 CakePHP 构建你自己的 SQL 字符串,那么它提供了如下的转义函数: escape(string $string, string $connection)

【讨论】:

  • 强烈反对!!!
  • 有时,某些外部库需要您为它们转义,我需要“借用”现有的连接和转义功能。
【解决方案2】:

如果您想为您的框架使用 cake,请不要担心mysql_real_escape_string。蛋糕已经解决了这个问题。但我会推荐看看Data Sanitization

**But to allow cake to take care of sql injection, you will have to use ORM methods like save(), find(), saveAll().**

【讨论】:

    【解决方案3】:

    一般来说:您不应该这样做。

    Cake 假设您将使用它的 ORM 而不是直接编写 SQL。

    如果你用query() 绕过它(这表示这应该只是很少需要)然后查看Data Sanitization(它链接到它。

    它表明你应该使用:

    Sanitize::escape($string, $connection)
    

    【讨论】:

    • Sanitize 在 3.x 中被移除,似乎没有任何替代品
    猜你喜欢
    • 2010-11-04
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    • 2013-01-17
    相关资源
    最近更新 更多