php - LIKE Statement not Working Properly in PDO -


i have piece of code return search results database:

$search_stmt = $dbconnection->prepare("select * `books` `title` '%testing1234%' order `rating` desc, `title` asc limit 1000"); 

this piece of database:

--------------------- | id |title         | --------------------- | 1  |testing1234   | --------------------- | 2  |testament...  | --------------------- 

that doesn't return table.

replacing testing1234 testing, returns row 1.

i've tried replacing testing1234 test, returns both rows.

i've replaced like '%testing1234%' regexp 'testing1234', same results regexp got of like statements.

when put original query sequel pro, returns row 1.

so conclusion i'm not using pdo properly, me going in right direction appreciated!

the answer make sure the charset defined whne establishing connection database.

this original code connecting:

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

this way should done:

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

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -