我使用此代码:
$search = $this->wpdb->prepare("WHERE (name LIKE %s OR tag LIKE %s)", \'%\'. $this->wpdb->esc_like($word) .\'%\', \'%\'. $this->wpdb->esc_like($word) .\'%\');
在控制台中,我得到:
name LIKE \'{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}night{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}\' OR tag LIKE \'{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}night{4b9ad9b602bd32ff99324feebaa1883bb3a3e818f587b35198d4e48093375c78}\'
我怎样才能去掉这根奇怪的绳子?
最合适的回答,由SO网友:Sally CJ 整理而成
这是由生成的占位符转义字符串wpdb::placeholder_escape()
所使用的wpdb::add_placeholder_escape()
这被称为wpdb::prepare()
.
所以保留这些转义字符串是安全的,但是wpdb
删除它们的方法: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 );