业务场景:php页面调用mysql存储过程,有1个入参,1个出参。
出现问题:能正常执行,但入参到数据库后总是显示乱码。
PHP页面代码如下
query("CALL x2('$info_name_cn',@exeout_rows)");
$result=$conn->query("SELECT @exeout_rows");
$recordset=mysqli_fetch_assoc($result);
$exeout_rows=(int)$recordset["@exeout_rows"];
?>
---|||---mysql存储过程代码如下
CREATE DEFINER=`数据库名`@`%` PROCEDURE `x2`( IN exein_info_name_cn VARCHAR(5) ,OUT exeout_rows int ) BEGIN set exeout_rows=1; insert into 测试表 ( info_name_cn ) values ( exein_info_name_cn ); END
mysql数据库中,测试表的选项为"utf8/utf8_ganaral_ci",测试表内部字段info_name_cn的字符集和排序顺序为"utf8/utf8_ganaral_ci"
我尝试不同转换不同编码方式——如下文字
但是结果都是乱码——执行后结果如下图片
(id为)29:不转换
//$info_name_cn=mb_convert_encoding($info_name_cn,'UTF-8');
(id为)30:转换为UTF-8
$info_name_cn=mb_convert_encoding($info_name_cn,'UTF-8');
(id为)31:转换为GB2312
$info_name_cn=mb_convert_encoding($info_name_cn,'GB2312');
(id为)32:转换为GBK
$info_name_cn=mb_convert_encoding($info_name_cn,'GBK');
(id为)33:转换为BIG5
$info_name_cn=mb_convert_encoding($info_name_cn,'BIG5');
(id为)34:转换为ASCII
$info_name_cn=mb_convert_encoding($info_name_cn,'ASCII');

另外,运行以下代码可以正常往数据库添加中文

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
*.php文件编码问题
补充:同样情况下,我将文件保存编码方式改为ASCI,页面代码设置为GBK后运行正常。