PHP read MSSQL JSON data Chinese garbled solution mssql2005 Database mssql2008 Installation Tutorial MSSQL database is what

Source: Internet
Author: User
PHP and Web pages use UTF-8 encoding, the database is SQL server2008, using the default encoding (936, which is GBK encoding)

When reading the database data, use PHP's own json_encode () to return to the front end, the result Chinese is not displayed.

The solution is as follows:

In this way, the Chinese in SQL Server 2008 can be displayed correctly on the Web page.

If you want to insert Chinese correctly into SQL Server 2008, add a code: $query = Iconv ("Utf-8", "Gbk//ignore", $query);//In order to solve the problem of Chinese garbled

The complete code is as follows:

<?php/*** If the employee number does not exist in MySQL then insert the employee record in MySQL * If the employee number already exists then update the operation *///if you want to use text/html in JSON format, you cannot use Text/xmlheader (" Content-type:text/html;charset=utf-8 ");//Header (" CONTENT-TYPE:TEXT/HTML;CHARSET=GBK ");//Tell the browser not to cache the data header (" Cache-control:no-cache "); require '. /conn.php '; $seq = $_post["seq"]; $employeeID = $_post["EmployeeID"]; $employeeName = $_post["EmployeeName"];$ Department = $_post["department"];if (!isset ($seq) | | $seq = = "") {//SEQ does not exist insert new record $query = "INSERT INTO employees (EMPLOYEEI D, EmployeeName, Department, Createtime, UpdateTime) VALUES (n ' $employeeID ', n ' $employeeName ', n ' $department ', GETDATE ( ), GETDATE ()) ";} else{//Update existing record if seq already exists $query = "Update Employees SET employeeid= ' $employeeID ', employeename= ' $employeeName ', Department= ' $department ', updatetime=getdate () WHERE seq= ' $seq ' ";} File_put_contents ("E:/mylog.log", $query. " \ r \ n ", file_append);//For commissioning$query = Iconv ("Utf-8", "Gbk//ignore", $query);//In order to solve the problem of Chinese garbledif ($result = sqlsrv_query ($conn, $query)) {echo true;} Else{echo false;} Echo $query;? >

The above is a small part of the introduction of PHP to read the MSSQL JSON data Chinese garbled solution, I hope to help you!

The above describes the PHP read MSSQL JSON data in Chinese garbled solution, including the MSSQL, the solution to the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.