将 Maya 2011 与 Mysqldb 连接

发布于 2024-12-09 13:57:13 字数 802 浏览 0 评论 0原文

我在 Windows 7(64 位)机器上使用 Maya 2011(64 位)和 MySQL 5.5(64 位)。我尝试通过python连接maya和Mysqldb。所以我将连接器文件复制到maya\python\lib\site 包中。

我能够导入 MYsqldb 模块,没有任何错误。但是当我尝试调用光标对象(用于查询)时,我发现Maya无法识别光标对象。

这是我的示例代码:

import MySQLdb as mb
import maya.cmds as cmds

def mysql_connect(hostname, username, password, dbname):
    db = mb.connect(host=hostname,user=username,passwd=password,db=dbname)

db = mysql_connect("localhost", “root”, “test”, “mydbt")
dbcursor = db.cursor()
dbcursor.execute("select * from maya")


But the code throws the following error :

错误:AttributeError:'NoneType'对象没有属性'cursor'#

我尝试验证环境路径变量,替换连接器文件,但问题仍然存在。

由于是初学者,我无法确定确切的问题。
我请求您提出宝贵的建议

I am using Maya 2011(64bit) and MySQL 5.5 (64 bit) in Windows 7 (64 bit) machine. I tried to connect maya with Mysqldb through python. So i copied the connector files into maya\python\lib\site packages.

I was able to import MYsqldb module without any error. But when i tried call the cursor object (for querying), I found that Maya is not recognizing the cursor object.

Here is my sample code:

import MySQLdb as mb
import maya.cmds as cmds

def mysql_connect(hostname, username, password, dbname):
    db = mb.connect(host=hostname,user=username,passwd=password,db=dbname)

db = mysql_connect("localhost", “root”, “test”, “mydbt")
dbcursor = db.cursor()
dbcursor.execute("select * from maya")


But the code throws the following error :

Error: AttributeError: ‘NoneType’ object has no attribute ‘cursor’ #

I tried verifying the env-path variables, replacing the connector files but the problem persists.

Since being a beginner, i am un-able to identify the exact issue.
I request for your valuable suggestions

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愁杀 2024-12-16 13:57:13

您没有从 mysql_connect 函数返回任何内容。所以它返回None。当您这样做时:

db = mysql_connect("localhost", “root”, “test”, “mydbt")

db 变为None。尝试改变:

db = mb.connect(host=hostname,user=username,passwd=password,db=dbname)

话虽

return mb.connect(host=hostname,user=username,passwd=password,db=dbname)

这么说,我不确定定义一个函数来制作单个东西是否有用。最好有这样的东西:

import MySQLdb as mb
import maya.cmds as cmds

db = mb.connect(host="localhost",user=“root”,passwd=“test”,db=“mydbt")

dbcursor = db.cursor()
dbcursor.execute("select * from maya")

You are not returning anything from mysql_connect function. So it returns None. When you do:

db = mysql_connect("localhost", “root”, “test”, “mydbt")

db becomes None. Try changing:

db = mb.connect(host=hostname,user=username,passwd=password,db=dbname)

with

return mb.connect(host=hostname,user=username,passwd=password,db=dbname)

That being said, I'm not sure defining a function to make a single thing is useful. Better to have something like this:

import MySQLdb as mb
import maya.cmds as cmds

db = mb.connect(host="localhost",user=“root”,passwd=“test”,db=“mydbt")

dbcursor = db.cursor()
dbcursor.execute("select * from maya")
倾`听者〃 2024-12-16 13:57:13

在这里,您有两件事分配给db。看来 mysql_connect("localhost", "root", "test", "mydbt") 返回 None,所以当你调用 db.cursor( ) 之后,您会收到该错误。

请确保您正确覆盖了 db 变量(在本例中,您似乎没有正确覆盖)。

Here, you have two things assigned to db. It appears that mysql_connect("localhost", “root”, “test”, “mydbt") is returning None, so when you call db.cursor() later, you get that error.

Make sure you're overwriting the db variable correctly (in this case, it looks like you aren't).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文