gpt4 book ai didi

python - 如何在 python 中使用 OurSQL 仅在 UNICODE 中与 MySQL 数据库通信?

转载 作者:行者123 更新时间:2023-11-30 23:37:19 24 4
gpt4 key购买 nike

我在看oursql的文档遇到了这个description for establishing a connection :

By default, oursql will try to use unicode wherever possible, and set the connection charset to utf8.

我的表和所有列都以 utf8 格式存储每个字符串。

这是否意味着,当我像这样连接到我的数据库时

conn = oursql.connect(host='127.0.0.1', user='habnabit', passwd='foobar',
db='example', port=3307)

我可以将 unicode 字符串传递给游标,然后游标会自动将它们转换为 utf8 吗?反之,游标将从数据库中以 unicode 形式返回任何字符串?所以我不必费心解码或编码?

我现在必须确定这一点。 :-)

最佳答案

你应该可以,是的。我猜你只需要 set the MySQL character set connection variables . SET NAMES 通常就足够了。

关于python - 如何在 python 中使用 OurSQL 仅在 UNICODE 中与 MySQL 数据库通信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6445508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com