1

I have all tables and database encoded with utf8_general_ci and all data in database are ok. When I select data with PHP (PDO) and print in CLI (and when I save these data into db) texts contains question marks:

Raw, zagra? te? rol? wiceprezydenta

Why ? What's wrong ? I tried SET NAMES solution but don't work. Part of my code:

<?php
setlocale(LC_ALL, 'pl_PL');
ini_set('default_charset','utf-8');
mb_internal_encoding("UTF-8");
putenv('LANG=pl_PL.UTF-8');
$db = new PDO('mysql:host=localhost;dbname=nameofdb;charset=utf-8','root','******', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
// body...
mitch
  • 2,235
  • 3
  • 27
  • 46
  • Does your *CLI* interpret UTF-8 correctly...? – deceze Oct 14 '13 at 09:09
  • Yes. The problem is even when I run script from browser (and of course set header charset to utf8) – mitch Oct 14 '13 at 09:10
  • Have you considred *everything* in [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through)? – deceze Oct 14 '13 at 10:09

1 Answers1

0

The charset in your $db connection string should be utf8 not utf-8 like this:

$db = new PDO('mysql:host=localhost;dbname=nameofdb;charset=utf8','root','****', 
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
Mark
  • 8,046
  • 15
  • 48
  • 78