php - LIKE Statement not Working Properly in PDO
I have this piece of code to return search results from my database:
{-code-{-code-5}}
This is a piece of my database:
That doesn't return anything from my table.
Replacing{-code-3}
with{-code-4}
, this returns row{-code-5}
.
I've also tried replacing{-code-3}
with{-code-7}
, this returns both rows.
I've also replaced{-code-{-code-12}{-code-12}} '%{-code-3}%'
with{-code-{-code-12}0} '{-code-3}'
, but I get the same results with{-code-{-code-12}0}
as I got with all of my{-code-{-code-12}{-code-12}}
statements.
When I put my original query into Sequel Pro, it returns row{-code-5}
.
So my conclusion is that I'm not using PDO properly, any help to get me going in the right direction would be much appreciated!
Answer
Answer
Answer
Answer
Answer
Solution:
The answer is to make sure the the
charset
is defined whne establishing a connection to the database.This is the original code for connecting:
This is the way it should be done: