wpdb prepare placeholders for MySQL keywords

I have a function that takes inputs that will be used for keywords in the query. I want to use placeholders for these th

I have a function that takes inputs that will be used for keywords in the query. I want to use placeholders for these things in the query string, as otherwise there will be a sqli vulnerability.

Here's my function:

 function get_things ($args = array()) {
  global $wpdb;

  $sql = $wpdb->prepare(
    "SELECT * FROM " . $wpdb->prefix . "my_table ORDER BY %s %s",
     $args['order_by'],
     $args['order']
  );

  $results = $wpdb->get_results($sql);
}

The second placeholder will be a MySQL keyword (either ACS or DESC). The problem with the above function is that the keyword will be wrapped in quotes. How can I fix this, whilst not creating a sqli vulnerability?

Also, the first placeholder (which will be a column name) is also being wrapped in quotes, which I don't want and is causing issues.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745516790a4631048.html

相关推荐

  • wpdb prepare placeholders for MySQL keywords

    I have a function that takes inputs that will be used for keywords in the query. I want to use placeholders for these th

    14小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信