最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wpdb prepare placeholders for MySQL keywords

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论