无法显示从AES_DECRYPT检索到的特殊字符

时间:2016-08-30 17:12:44

标签: php mysql codeigniter encryption

我正在使用codeigniter 运行以下查询后:

$names = this->db->query("SELECT AES_DECRYPT(nombre,'".$key."') AS nombre FROM places")

我从var_dump($ names)

获得以下输出
[43]=>
array(1) {
  ["nombre"]=>
  string(41) "Industriales de Campeche"
}
[44]=>
array(1) {
  ["nombre"]=>
  string(67) "Evaristo Garc�a ESE"
}
[45]=>
array(1) {
  ["nombre"]=>
  string(39) "San Jose Popay�n"

phpmyadmin上的查询结果如下所示:

enter image description here

如您所见,包含特殊字符的字段以十六进制表示形式显示。当我使用这个工具http://www.rapidtables.com/convert/number/hex-to-ascii.htm我可以毫无问题地转换十六进制字段(显示特殊字符),但事情是我无法使它在codeigniter中工作。即使我使用utf-8编码,特殊字符仍然显示为 。

值得一提的是,在加密数据库之前我没有遇到任何问题。

2 个答案:

答案 0 :(得分:0)

你需要做两件事

  1. 将表格和字段整理设置为" utf8_general_ci"
  2. 在HTML中设置元内容类型,如下所示

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    

答案 1 :(得分:0)

  • Check your MySQL data column is using _unicode_ or utf8mb4_ character collations. Also check your table as a whole is using the same character set (in PHPMyAdmin look in <table> -> Operations -> Collation ).

  • Check that your MySQL connection is using UTF8mb4_ connection character set (see below).

  • Check that your HTML headers are set to UTF-8 (the headers, not the <head> section of the page, although that can't hurt to set to UTF-8 too.).

I'm pretty sure your issue comes that your connection to your database from your PHP (or whatever) is not the required full UTF-8 character set.

 // In your database connection class. 
 // Once initial contact has been established
 $this->dbObject->set_charset("utf8mb4");

Some further reading: UTF-8 all the way through

相关问题