0

im not new in php coding and have a problem. I need insert data to sql (czech language encoding).

I wanna input this string: +ěščřžýáíéůú My DB output is: +ì¹èø¾ýáíéùú

So, im trying this solutions:

1) My config.php has this one:

header('Content-Type: text/html; charset=utf-8');
ini_set("default_charset", 'utf-8');

2) On top of the page is this meta-tags:

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <meta charset="utf-8" />

3) When im connecting into db, im using:

 @define("DB_Connect_Charset", "utf8");    
 $dsn = 'mysql:dbname='.DB_Connect_Database.';host='.DB_Connect_Hostname.';charset='.DB_Connect_Charset;

+

$this->pdo = new PDO($dsn, DB_Connect_Username, DB_Connect_Password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES ".DB_Connect_Charset));

Im trying some php functions like: iconv OR mb_convert_encode()

Database has utf8_czech_ci coding, when im trying to change it into windows-1251 or latin.. it doesnt help.

I spend a lot of time on stackoverflow and cannot find a solution about this problem, some problems will be deleted with SET NAMES UTF8.

Problem must be in part when im sending data to SQL, because if im put data manually into sql, im fetching it correctly.

Thank you for your time and help. Have a nice day!

emololftw
  • 31
  • 6
  • 3
    All it takes, is one wrong charset setting in your application - *everything* needs to be the same charset! I have previously written [**an answer about UTF-8 encoding**](https://stackoverflow.com/a/31899827/4535200) that contains a little checklist, that will cover *most* of the charset issues in a PHP/MySQL application. There's also a more in-depth topic, [**UTF-8 All the Way Through**](https://stackoverflow.com/q/279170/4535200). Most likely, you'll find a solution in either one or both of these topics. – Qirel Apr 08 '19 at 14:42

1 Answers1

0

When I'm binding parameters I use utf8_encode function for value. It was a mistake.

halfer
  • 19,824
  • 17
  • 99
  • 186
emololftw
  • 31
  • 6