The project needs to use the Mobile Agent Mas SMS Interface development, but the manufacturers to provide the development package without PHP, can only use the DB interface, direct operation of MySQL. But after the text message sent, the mobile phone received the text message is really garbled, pondering for a long time, the approximate judgment should be the problem of character encoding. Continue to study and experiment in this direction, and finally find out the reason. 1. Log into the MySQL database of the MAS machine,
Use command: Show variables like "%char%";
To view the character encoding of the MySQL database:
2 . PHP is used as follows: mysql_connect (' ip:3306 ', ' user ', ' pwd ');
mysql_select_db (' Mas ');
mysql_query ("Set names latin1;");
mysql_query (mb_convert_encoding ("INSERT into API_MT_DB01 (mobiles,content) VALUES ('". $mobiles. "', '". $content. "');" , "GB2312", "UTF-8"));
Where set names Latin1 is equivalent to
SET character_set_client = latin1; SET character_set_results = latin1; SET character_set_connection = latin1;
3, the character encoding in the project is UTF-8, the running environment is Windows 2008, its character encoding is GB2312,
Because the latin1 and UTF8 character sets are incompatible, the conversion is irreversible, so you have to turn UTF8 into gb2312, then turn GB2312 into Latin1
so the information input path: app->os->client->connection->mysql, encoding and encoding conversion process utf8->gb2312->latin1->latin1-> Latin1
PHP to send mobile Mas SMS garbled solution method