About JSON heavy MySQL read data problem

Source: Internet
Author: User
Tags php json
PHP json JavaScript

Connect Database Code
$conn =mysql_connect ("127.0.0.1", "root", "root") or Die ("Connection database failed!");
mysql_select_db ("Resume2", $conn) or Die ("No 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);

And then read the data that you just deposited from the database
$query =mysql_query ("select * from ' Resume ' WHERE ' job_id ' = 10"); The ID you just deposited is 10.
$row =mysql_fetch_array ($query);
$num =json_decode ($row [' job_content '],true);
echo $num [' name '];

Question, when I job_name for "Zhang Small white", output $num[' name '] is "u6234u660eu534e", ask the big God to see where the problem is. Why is the output not the name "Zhang Xiao Bai"? "


Reply to discussion (solution)

JSON only accepts UTF-8 encoded characters, confirming that your page is UTF-8 encoded.

JSON only accepts UTF-8 encoded characters, confirming that your page is UTF-8 encoded.

When I created the project and HTML file is unified with Utf-8, with Json_encode transcoding to save to the database, such as I write "white", but in the database is
"u6234u660eu534e" in this form. Read the database can only read "u6234u660eu534e" This, do not know how to turn it into a "small white" this Chinese code.

echo $_post[' job_name ']; Is it normal?

echo $_post[' job_name ']; Is it normal?

Normal.

Why is "Zhang Xiao Bai"?

$s = ' "\u6234\u660e\u534e";
echo Json_decode ($s); Daiminghua

Echo Json_encode (' Zhang Xiao Bai '); "\u5f20\u5c0f\u767d"

You don't have an accurate description of your problem.

Problem, has been resolved. It's the MySQL transfer 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.