php - MySQL Query only works within WordPress -


i tried extensively find answer question seems specific.

my query contains latin characters:

$mydb->query("select cotação compras"); 

it's working fine when called in wordpress shortcode, in custom php on same site gives me this:

you have error in sql syntax; check manual corresponds mysql server version right syntax use near '??o compras' @ line 1

now, don't want remove characters because know query works , i'd rather understand problem.

so what's going on here? thanks.

to work on local machine, not work until set collation , names utf8. appears wealth of data find in searching primary problem people encounter non-ascii characters.

to work local pdo instance, did following:

    $pdo->exec("set collation_connection = utf8_bin");     $pdo->exec("set names utf8");     $all = $pdo->query("select * temp_cotação limit 5")->fetchall(); 

you can find more information here:

pdo cutting off strings @ utf-8 character

it seems me better globally rather per connection...i found set names utf8 globaly each connection:

how make pdo run set names utf8 each time connect, in zendframework

to same thing in mysqli_, here:

php mysql set names 'utf8' collate 'utf8_unicode_ci' doesn't work mysqli (solved)


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -