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