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

Strange string in console from wpdb query

programmeradmin0浏览0评论

I use this code:

   $search = $this->wpdb->prepare("WHERE (name LIKE %s OR tag LIKE %s)", '%'. $this->wpdb->esc_like($word) .'%', '%'. $this->wpdb->esc_like($word) .'%'); 

and in console i get:

name LIKE '{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}night{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}' OR tag LIKE '{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}night{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}'

how i can remove this strange string?

I use this code:

   $search = $this->wpdb->prepare("WHERE (name LIKE %s OR tag LIKE %s)", '%'. $this->wpdb->esc_like($word) .'%', '%'. $this->wpdb->esc_like($word) .'%'); 

and in console i get:

name LIKE '{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}night{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}' OR tag LIKE '{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}night{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}'

how i can remove this strange string?

Share Improve this question asked May 28, 2020 at 22:09 manandmanmanandman 352 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

That is a placeholder escape string generated by wpdb::placeholder_escape() which is used by wpdb::add_placeholder_escape() and which is called by wpdb::prepare().

So it is safe to keep those escape strings, but there is a wpdb method for removing them: wpdb::remove_placeholder_escape():

// In your case, you'd use $this->wpdb in place of $wpdb.
$query = $wpdb->add_placeholder_escape( 'LIKE %night%' );
$query2 = $wpdb->remove_placeholder_escape( $query );
var_dump( $query, $query2 );
发布评论

评论列表(0)

  1. 暂无评论