【问题标题】:How to secure insert statements in wordpress?如何保护 wordpress 中的插入语句?
【发布时间】:2014-03-14 01:52:50
【问题描述】:

我是 Wordpress 的新手,我已经阅读了大量有关如何使用准备好的语句将数据插入数据库的内容。 我的问题是这段代码有多安全?:

    $wpdb->query(
     $wpdb->prepare("INSERT INTO {$wpdb->prefix}tablename(id,custom_field) 
        VALUES(%d, %s)",$ID, $customfield)
    );  

我还能做些什么来保护此代码吗? 我知道这可能是一个愚蠢的问题,但我想知道如何正确回答。

提前致谢。

【问题讨论】:

  • 我必须重新检查有关 $wpdb 的文档,但似乎是合法的。无论如何,你为什么不使用update_post_meta(因为它是完全安全的)?

标签: mysql wordpress


【解决方案1】:

您可以轻松使用$wpdb->insert( $table, $data, $format )。 用法:

$wpdb->insert( 
'table', 
array( 
    'column1' => 'value1', 
    'column2' => 123 
), 
array( 
    '%s', 
    '%d' 
) 

);

更多信息在:http://codex.wordpress.org/Class_Reference/wpdb#INSERT_rows

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-05
    • 2011-02-15
    • 1970-01-01
    • 2011-11-21
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    相关资源
    最近更新 更多