php - LIKE Statement not Working Properly in PDO

304

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!

844

Answer

- | id |title |
89

Answer

- | 1 |testing1234 |
748

Answer

- | 2 |Testament... |
532

Answer

-|||testing1234|||testing|||1|||testing1234|||test|||LIKE '%testing1234%'|||REGEXP 'testing1234'|||REGEXP|||LIKE|||1
341

Answer

Solution:

The answer is to make sure the thecharset is defined whne establishing a connection to the database.

This is the original code for connecting:

$dbConnection = new PDO('mysql:host=' . $db_host . ';dbname=' . $db_name . '', $db_user, $db_pass);

This is the way it should be done:

$dbConnection = new PDO('mysql:host=' . $db_host . ';dbname=' . $db_name . ';charset=utf8', $db_user, $db_pass);

People are also looking for solutions to the problem: php - Graph API Get all photos

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.