Milksnake12
Milksnake12

Reputation: 561

PDO MySQL like query not returning value

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

Answers (1)

Sean
Sean

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

Related Questions