MySQL solution to pass Chinese parameter to stored procedure into garbled

Source: Internet
Author: User

Today's program requires a stored procedure, which is then called with a PHP program.
The stored procedure is as follows: Delimiter $ $CREATE PROCEDURE disagree_upgrade_detail (a int,b text) beginset NAMES ' UTF8 '; UPDATE ' upgrade_detail ' SET ' disagree_description ' =b WHERE ' id ' =a;insert into ' disagree_upgrade_detail ' SELECT * from ' Up Grade_detail ' where ' id ' =a;delete from ' upgrade_detail ' where ' id ' =a; The code snippet for the end;$ $PHP is as follows: mysql_query ("Call Disagree_upgrade_detail ({$which}, ' {$why} ');"); Then I found a problem while running the program. Since $why the value of this variable is in most cases Chinese, after being passed to the stored procedure, it becomes a with? The garbled characters. After this I checked the PHP, the database encoding has been unified, has been engaged for a long time or helpless. Finally I found the answer in the http://topic.csdn.net/u/20070703/09/fbceeb45-1c8d-4009-ac84-cabe9fc315d7.html. The following modifications have been made to delimiter $ $CREATE PROCEDURE disagree_upgrade_detail (a int,bNvarchar (4000)) BEGINSET NAMES ' UTF8 ';UPDATE ' upgrade_detail ' SET ' disagree_description ' =b WHERE ' id ' =a;insert into ' disagree_upgrade_detail ' SELECT * from ' Up Grade_detail ' where ' id ' =a;delete from ' upgrade_detail ' where ' id ' =a; The code snippet for the end;$ $PHP is as follows: mysql_query ("Call Disagree_upgrade_detail ({$which},N' {$why} '); The code that needs attention has been marked green. When you create a stored procedure,The data type of the parameter of the design Chinese must be nvarchar, but also need to add an n when passing the parameter。

MySQL solution to pass Chinese parameter to stored procedure into garbled

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.