Adding duplicate values in wpdb->prepare()
Hi can I add a duplicate value in $wpdb->prepare.
I have the following SQL
"SELECT
id,
MATCH (content) AGAINST('$search')
FROM table
WHERE MATCH(post_search) AGAINST('$search' IN BOOLEAN MODE)"
to this
$wpdb->prepare("SELECT
id,
MATCH (content) AGAINST(%s)
FROM table
WHERE MATCH(post_search) AGAINST(%s IN BOOLEAN MODE)", $search_terms)
Is there a way of doing this without doing this
$search_terms1 = $search开发者_如何学JAVA_terms;
$search_terms2 = $search_terms;
$wpdb->prepare("SELECT
id,
MATCH (content) AGAINST(%s)
FROM table
WHERE MATCH(post_search) AGAINST(%s IN BOOLEAN MODE)", $search_terms1, $search_terms2)
Is there a way of doing this without doing this (... duplicating the variable passed)
Not using $wpdb
. (Nor with PDO
, for that matter.) You could stick to passing the initial variable, though, since it's not passed by reference.
Why not use the same as in SQL:
$wpdb->prepare("SELECT
id,
MATCH (content) AGAINST('$search_terms')
FROM table
WHERE MATCH(post_search) AGAINST('$search_terms' IN BOOLEAN MODE)")
精彩评论