· 8 years ago · Aug 24, 2018, 01:34 PM
1Cannot store UTF8 characters in MySQL
2CREATE TABLE IF NOT EXISTS `gen_admin_words_translated` (
3 `id` int(10) NOT NULL AUTO_INCREMENT,
4 `word_id` int(10) NOT NULL,
5 `value` text COLLATE utf8_unicode_ci,
6 `lang_id` int(2) NOT NULL,
7 `needUpd` int(1) NOT NULL DEFAULT '1',
8 PRIMARY KEY (`id`)
9) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2689 ;
10
11$charset = "UTF8";
12$link = mysql_connect($host, $user, $pass);
13if(!$link){
14 die("Unable to connect to database server.");
15}
16mysql_selectdb($database);
17if(function_exists("mysql_set_charset")){
18 mysql_set_charset($charset, $link);
19}else{
20 mysql_query("SET NAMES $charset");
21}
22
23<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
24
25$text = 'ţ, î, ş';
26mysql_query("insert into gen_admin_words_translated (word_id, lang_id, value, needUpd) values (1, 1, '$text', 1)");
27
28SELECT * FROM `gen_admin_words_translated`
29
30id word_id value lang_id needUpd
315166 1034 ?, 1 1
32
33header('Content-type: text/html; charset=utf-8');
34
35$charset = "UTF8";
36$link = mysql_connect('localhost', 'root', '') or die('connection?');
37mysql_select_db('test') or die('database?');
38if(function_exists("mysql_set_charset")){
39 mysql_set_charset($charset, $link);
40}else{
41 mysql_query("SET NAMES $charset");
42}
43
44$text = 'ţ, î, ş';
45mysql_query("insert into gen_admin_words_translated (word_id, lang_id, value, needUpd) values (1, 1, '$text', 1)");
46
47$query = mysql_query('SELECT * FROM `gen_admin_words_translated`');
48$array = mysql_fetch_array($query);
49
50print_r($array)
51
52Array
53(
54 [0] => 2689
55 [id] => 2689
56 [1] => 1
57 [word_id] => 1
58 [2] => ţ, î, ş
59 [value] => ţ, î, ş
60 [3] => 1
61 [lang_id] => 1
62 [4] => 1
63 [needUpd] => 1
64)
65
66header('Content-type: text/html; charset=utf-8');
67
68$text = 'ţ, î, ş';
69
70$text = 'ţ, î, ş';
71
72$text = "xC5xA3, xC3xAE, xC5x9F";
73
74[client]
75port=3306
76
77[mysql]
78default-character-set=utf8
79port = 3306
80#
81[mysqld]
82basedir=".....
83#Path to the database root
84datadir=".....
85# The default character set that will be used when a new schema or table is
86# created and no character set is defined
87character-set-server=utf8