Questions about json-heavy mysql data reading php json javascript
// Database connection code
$ Conn = mysql_connect ("127.0.0.1", "root", "root") or die ("database connection failed! ");
Mysql_select_db ("resume2", $ conn) or die ("no such database! ");
Mysql_query ("set names utf8 ");
// Save an array to the database
$ Value = array ("name" =>$ _ POST ['job _ name']);
$ Var = json_encode ($ value );
Mysql_query ("insert into 'resume '('job _ id', 'job _ pass_status', job_content ') VALUES (NULL, 1,' $ var ')", $ conn );
// Then read the stored data from the database
$ Query = mysql_query ("SELECT * FROM 'resume' WHERE 'job _ id' = 10"); // The id just saved is 10
$ Row = mysql_fetch_array ($ query );
$ Num = json_decode ($ row ['job _ content'], true );
Echo $ num ['name'];
// Problem. when job_name is "Zhang Xiaobai" and $ num ['name'] is output as "u6234u660eu534e", please check out what went wrong. Why isn't the name "Zhang Xiaobai" output? "
Reply to discussion (solution)
Json only accepts UTF-8 encoded characters. make sure that your page is UTF-8 encoded.
Json only accepts UTF-8 encoded characters. make sure that your page is UTF-8 encoded.
When I create a project and html file, I use UTF-8 in a unified manner. I use json_encode to transcode the file and save it to the database. for example, I write "Zhang Xiaobai", but it is in the database.
"U6234u660eu534e. Reading the database can only read "u6234u660eu534e". I don't know how to convert it into a Chinese code such as "Zhang Xiaobai.
Echo $ _ POST ['job _ name']; // Is it normal?
Echo $ _ POST ['job _ name']; // Is it normal?
Normal
Why is it "Zhang Xiaobai?
$ S = '"\ u6234 \ u660e \ u534e "';
Echo json_decode ($ s); // Dai Minghua
Echo json_encode ('Zhang xiaobai'); // "\ u5f20 \ u5c0f \ u767d"
You have not described your problem accurately.
The problem has been solved. Mysql conversion problem