UTF8 in MySQL != UTF8 in PHP? -
this question has answer here:
- utf-8 way through 14 answers
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?
indeed, mysql's
utf8
not universally understood utf-8. though not issue here... mysql'sutf8
subset of actual utf-8 covering bmp , not supporting 4-byte characters. means high characters discarded; otherwise it's still utf-8 compatible.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
Post a Comment