I got this error while trying to get variable from a DataBase in MySql
0x000002A MySQL Connection Error!
MySql error is provided when version/value we’re trying to get from database is not a number
output when trying to print value Program is trying to get from database:
None
I tried to get variable named: "gameVersion" from DataBase Named: "gameversions", using Name of game but Instead of getting variable which has: "beta" I got mysql connector error
file and code that caused this error: functions.py:
import mysql.connector
database = mysql.connector.connect(
host = "localhost",
user = "root",
passwd = "s+W2DrcPQK5dada2^!dV!RUSZ@2$PbEX*3eacT",
database = "PythonDB",
)
my_cursor = database.cursor(buffered=True)
user = ""
game = ""
db_version = my_cursor.execute(f"SELECT gameVersion FROM gameversions WHERE gameName = 'Grand Thiefs'")
sqlStuff = "INSERT INTO users (usersUid, usersEmail, usersPwd, UsersPerms, usersMoney, gameVersion) VALUES (%s, %s, %s, %s, %s, %s)"
sqlStuffv = "INSERT INTO gameversions (gameVersion, gameName) VALUES (%s, %s)"
def CreateDataBase(name):
my_cursor.execute(f"CREATE DATABASE {name}")
#my_cursor.execute("CREATE TABLE gameVersions (gameVersion varchar(255) NOT NULL, gameName varchar(255) NOT NULL);")
def ShowTables():
my_cursor.execute("SHOW TABLES")
def ShowDataBases():
my_cursor.execute("SHOW DATABASES")
def CreateUser(Name, Password, Email, Version):
global user
user = [{Name}, {Email}, {Password}, "User", "0", {Version}]
my_cursor.execute(sqlStuff, user)
database.commit()
def checkversion(version, name):
if version != db_version:
if type(db_version) == float:
return "Failure"
else:
return "MySQL Connection Error"
else:
return "Correct"
2
Answers
I fixed my problem by changing code from:
To:
Thanks to youtube tutorial Help is not needed anymore
My code to connect at MySQL is :
Make sure you are connected to Mamp, Xampp, Wamp and others but try this to connect