Reputation: 561
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!
Upvotes: 0
Views: 112
Reputation: 12433
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));
Upvotes: 1