我想将树莓派连接到在线数据库并更改记录,但是我尝试了服务器时间,这给了我一些错误,例如“连接超时”,“使用密码= yes拒绝root用户访问” < / p>
import mysql.connector
mydb = mysql.connector.connect(
host="sql106.epizy.com",
user="epiz_24910878",
passwd="jianliang176",
database="epiz_24910878_mydb"
)
mycursor = mydb.cursor()
def insertStudentCheckin():
try:
sql = "INSERT INTO tblUser (uName,uPW) VALUES (%s,%s)"
val = (str(2),'absent')
#insert the check in with card id and today time and date
#first time is insert so no nid to check the card id value
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "student today record inserted.")
except Exception as e:
print(e)
print("hello")
insertStudentCheckin()
print("world")
我想要的输出是我可以将记录插入到远程数据库中。