UTF8 in MySQL != UTF8 in PHP? -


this question has answer here:

so having issue json_encode returning null found solution here, don't understand why issue in first place. mysql tables drawing data defined like

create table `super_table` (   `id` int(11) not null auto_increment,   `name` varchar(100) default null,   `values` text,   `created` timestamp not null default current_timestamp,   primary key (`id`) ) engine=innodb auto_increment=1 default charset=utf8; 

so shouldn't values , name utf8 encoded when pull them out in php? simplified version of i'm doing:

$sql = "select * super_table"; $query = $mysqli->query($sql); $data = (object) $query->fetch_all(mysqli_assoc); foreach ($data $key => $val) {     $data->$key = utf8_encode($val); } $result = array('success'=>$success, 'data'=>$data); echo json_encode($result); 

why not doing utf8_encode step yield null result when try json_encode it?

  1. indeed, mysql's utf8 not universally understood utf-8. though not issue here... mysql's utf8 subset of actual utf-8 covering bmp , not supporting 4-byte characters. means high characters discarded; otherwise it's still utf-8 compatible.

  2. your actual issue mysql storing data in utf8, says nothing how receive data in database client. mysql converts text on fly stored encoding to connection encoding (and vice versa). when connecting database in php code, can choose encoding prefer receive data in. use $mysqli->set_charset('utf8') retrieve data in utf-8.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -