About reading data from json-heavy mysql

Source: Internet
Author: User
Tags php json
Questions about json-heavy mysql data reading php json javascript

// Database connection code
$ Conn = mysql_connect ("", "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?


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.