2

The following syntax is the current syntax I have that's works.

$dbh = connect();
$singer = strtolower($_GET["singer"]);

$SQL =
      "SELECT *
        FROM table
        WHERE field1 LIKE ?
        ORDER BY field2 ASC";

$sth = $dbh-> prepare ($SQL);
$sth->bindParam (1, $singer);
$sth->execute();

What changes do I need to make to the line of code WHERE field1 LIKE ? to perform the query with the wildcard %?

I've tried WHERE field1 LIKE '%?%' but that didn't work.

Do I have to prepend '%

and append %'

to the value stored in $singer?

user784637
  • 14,282
  • 32
  • 89
  • 149

1 Answers1

9

TRY

$str = "%".$singer."%";
$SQL =
      "SELECT *
        FROM table
        WHERE field1 LIKE ?
        ORDER BY field2 ASC";

$sth = $dbh-> prepare ($SQL);
$sth->bindParam (1, $str);

Reference ==> see 3rd Example

diEcho
  • 52,196
  • 40
  • 166
  • 239