Blender database using Python (errors)

天涯浪子 提交于 2020-01-25 08:05:08

问题


I'm using Blender 2.74 and Python 3.4 with the correct connector for MySQL. (By the way, I'm just a beginner in using Blender and Python.)

What I want is to make a login UI and save the inputted name into the database, but my code seems a bit off or wrong. When I try to run the code, it didn't save the value in the variable, but when i try to run it in python IDE (PyCharm) it worked.

Here's the code:

import sys

sys.path.append('C:\Python34\Lib\site-packages')
sys.path.append('C:\Python34\DLLs')

import mysql.connector

import bge
bge.render.showMouse(1)

cont = bge.logic.getCurrentController()
own = cont.owner

sensor = cont.sensors ["enter"]
pname = own.get("prpText")

enter = cont.sensors ["enter"]
numpadenter = cont.sensors ["numpadenter"]

if enter.positive or numpadenter.positive:
    db = mysql.connector.connect(user='root', password='', host='localhost', database='dbname')

    cursor = db.cursor()

    #1st:
    cursor.execute("INSERT INTO tblname VALUE(%s", (var))

    #2nd:
    #cursor.execute("INSERT INTO storymode VALUES({})" .format(pname))

#this are the other codes that i have tried so far:
#add_player = ("INSERT INTO tblname " "(TblColumnName) " "VALUES (%s)")
#data_player = (var)
#cursor.execute(add_player, data_player)

#cursor.execute("INSERT INTO tblname" "(TblColumnName)" "VALUES (%(var)s)")

db.commit()

db.close()  

When I run the 1st code the error is: mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your mysql server version for the right syntax to use near '%s' at line 1.

When I run the second code: Unknown column 'data' in 'field list'

Can someone help me to fix this? or Do I need some add-ons in blender for it to work?

Thank you very much for reading my post and for the people who will give their opinions.

来源:https://stackoverflow.com/questions/30687155/blender-database-using-python-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!