一開始我用的是:

db=MySQLdb.connect(db=sae.const.MYSQL_DB,user=sae.const.MYSQL_USER,passwd=sae.const.MYSQL_PASS,host=sae.const.MYSQL_HOST,port=int(sae.const.MYSQL_PORT))

数据库编码与python代码的编码都已设为utf8,在PHPMyAdmin中加入中文记录,在网页查询显示中却显示乱码。我在网上各种搜索都找不到解决方法。最后最终发如今连接数据库时加入charset參数为utf8就能够了。

db=MySQLdb.connect(db=sae.const.MYSQL_DB,user=sae.const.MYSQL_USER,passwd=sae.const.MYSQL_PASS,host=sae.const.MYSQL_HOST,port=int(sae.const.MYSQL_PORT),charset='utf8')


相关文章:

  • 2021-10-01
  • 2021-08-12
  • 2021-04-01
  • 2021-04-25
  • 2021-12-03
  • 2022-12-23
猜你喜欢
  • 2021-08-22
  • 2021-11-13
  • 2021-11-17
  • 2022-03-10
  • 2022-12-23
  • 2021-05-20
相关资源
相似解决方案