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...
4

1 回答 1

0

连接字符串中的字符集$db应该是这样的:utf8utf-8

$db = new PDO('mysql:host=localhost;dbname=nameofdb;charset=utf8','root','****', 
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
于 2013-10-14T09:11:48.397 回答