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!

2

1 Answer 1

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.