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
  • 15,392
  • 32
  • 93
  • 156

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

xkeshav
  • 53,360
  • 44
  • 177
  • 245