Skip to content

Commit

Permalink
CONCAT_WS instead of CONCAT
Browse files Browse the repository at this point in the history
  • Loading branch information
ozh committed Oct 28, 2014
1 parent da9923b commit 2802526
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
$search_text = $search;
$search = str_replace( '*', '%', '*' . yourls_escape( $search ) . '*' );
if( $search_in == 'all' ) {
$where .= " AND CONCAT(`keyword`,`url`,`title`,`ip`) LIKE ('$search')";
$where .= " AND CONCAT_WS('',`keyword`,`url`,`title`,`ip`) LIKE ('$search')";
// Search across all fields. The resulting SQL will be something like:
// SELECT * FROM `yourls_url` WHERE CONCAT(`keyword`,`url`,`title`,`ip`) LIKE ("%ozh%")
// SELECT * FROM `yourls_url` WHERE CONCAT_WS('',`keyword`,`url`,`title`,`ip`) LIKE ("%ozh%")
// CONCAT_WS because CONCAT('foo', 'bar’, NULL) = NULL. NULL wins. Not sure if values can be NULL now or in the future, so better safe.
// TODO: pay attention to this bit when the DB schema changes
} else {
$where .= " AND `$search_in` LIKE ('$search')";
Expand Down

0 comments on commit 2802526

Please sign in to comment.