0

I'm using a PDO to connect to a MySQL database. My query runs correctly and returns results as expected until I ad a 'like' at the end of the query in which no results are returned. I'm posting a mock query of my problem with just the trouble spot. Where am I going wrong with this?

$value = "text";
$stmt = $pdo->prepare('SELECT something FROM table WHERE days LIKE "%:value%"');
$stmt->execute(array(':value' => $value));

Thanks for any advice!

Milksnake12
  • 551
  • 1
  • 9
  • 19
  • 1
    [How can I use prepared statements with LIKE operator?](http://stackoverflow.com/questions/15990857/reference-frequently-asked-questions-about-pdo#15990965) – DCoder Jun 30 '13 at 06:15
  • Don't know how I didn't see that when I searched for this... Thanks! – Milksnake12 Jun 30 '13 at 06:18

1 Answers1

1

Try

$value = "text";
$stmt = $pdo->prepare('SELECT something FROM table WHERE days LIKE :value');
$stmt->execute(array(':value' => "%".$value."%"));

Or

$value = "%text%";
$stmt = $pdo->prepare('SELECT something FROM table WHERE days LIKE :value');
$stmt->execute(array(':value' => $value));
Sean
  • 12,443
  • 3
  • 29
  • 47