$a = array (' AA ' = ' BB ');
$s = json_encode ($a);
$s = gzdeflate ($s);//I missed the sentence when I raised the question, and it was a big mistake (2014/12/22 18:20:00)
$sql = "INSERT into Tbl_name (id,content) VALUES (1, '%s ')";
$sql = sprintf ($sql, $s);
Mysql_connect (' Host ', ' User ', ' pwd ');
mysql_query (' Set names UTF8 ');
mysql_query (' use db_name ');
mysql_query ($sql);
Mysql_close ();
The above code executes after the database has a new record, but the value of the Content field is empty, please show the hero, my question where?
Add
I printed sql: INSERT into tbl_name (id,content) VALUES (1, ' klü0\0 ')
The results database contains the following content:
Feel like the character set is not supported, have checked the database and table are UTF8?
And then, what are some of the things I should be aware of when I'm fetching data?
Reply content:
$a = array (' AA ' = ' BB ');
$s = json_encode ($a);
$s = gzdeflate ($s);//I missed the sentence when I raised the question, and it was a big mistake (2014/12/22 18:20:00)
$sql = "INSERT into Tbl_name (id,content) VALUES (1, '%s ')";
$sql = sprintf ($sql, $s);
Mysql_connect (' Host ', ' User ', ' pwd ');
mysql_query (' Set names UTF8 ');
mysql_query (' use db_name ');
mysql_query ($sql);
Mysql_close ();
The above code executes after the database has a new record, but the value of the Content field is empty, please show the hero, my question where?
Add
I printed sql: INSERT into tbl_name (id,content) VALUES (1, ' klü0\0 ')
The results database contains the following content:
Feel like the character set is not supported, have checked the database and table are UTF8?
And then, what are some of the things I should be aware of when I'm fetching data?
That's not 字符集
the problem, it 编码
's the problem.
gzdeflate
After the data is binary string, does not belong to any 字符集
, the character set is targeted 可打印(printable)文本串
You're utf8_encode
actually converting the gzdeflate after the 二进制串
encoding to encode iso_8859_1
字符串
utf-8
, so one step will only increase the length of the compressed binary string (all ascii>127 characters will be expanded to 2 bytes or more)
If the compression is considered, it is best to use BLOB
the same binary type storage, the access time does not need to encode the conversion
Problem solved, is indeed a character set problem, the Gzdeflate compressed data to utf8_encode a bit on it.
$a = array (' AA ' = ' BB ');
$s = json_encode ($a);
$s = gzdeflate ($s);
$s = utf8_encode ($s);//The answer is here, take out the time corresponding to do Utf_decode ()
$sql = "INSERT into Tbl_name (id,content) VALUES (1, '%s ')";
$sql = sprintf ($sql, $s);
Mysql_connect (' Host ', ' User ', ' pwd ');
mysql_query (' Set names UTF8 ');
mysql_query (' use db_name ');
mysql_query ($sql);
Mysql_close ();
Refer to the information here http://stackoverflow.com/questions/9413402/php-mysql-special-character-inserts-being-truncated
Compared to the size of the front of the gzdeflate data, the original 280,000 bytes of content compression after only 2000, compression ratio is quite high
Yes, you can. Gzdeflate data is then base64 to enhance compatibility, or the binary stream after deflate is stored directly in the database