我正在为 android 构建一个应用程序,我需要与 Mysql 数据库进行交互。我在从 android 配置访问时遇到了一些问题,但在我的 linux 安装中却没有。
我已经在我的 android apk 上成功导入了 SQLAlchemy 的配方,但是当我通过 logcat 运行应用程序时,我看到了错误:
NO module named MySQLdb
所以我尝试在 buildozer 中添加 MySQLdb 的配方,它说:
No matching distribution found for MySQLdb
这是调用mysql部分的代码部分:
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy import MetaData, Column, Table, ForeignKey
from sqlalchemy import Integer, String
from sqlalchemy.sql import select
def check_sql_list(_id, string):
cur = engine.connect()
res = cur.execute("SELECT * FROM tbl_user")
for x in res.fetchall():
if x[_id] == string: return True
cur.close()
def create_user(name,e_mail,psw):
if check_sql_list(1,name):
print 'Select another username.'
elif check_sql_list(2,e_mail):
print 'Your E-Mail have already an account.'
else:
connection = engine.raw_connection()
try:
cursor = connection.cursor()
cursor.callproc("sp_createUser",[name, e_mail, psw])
results = list(cursor.fetchall())
for a in cursor.fetchall():
print a
print results
cursor.close
connection.commit()
finally:
connection.close()
print 'Account registered succesfully.'
ip = 'localhost'
databs = 'mydb'
user = 'guest'
psw = 'password'
porta = '3306'
engine = create_engine('mysql://' + user + ':' + psw + '@' + ip + ':' + porta + '/' + databs)
create_user('user001','mail@001.com','password')
如何在不需要 MySQLdb 配方的情况下连接到我的数据库?或者我在哪里可以找到那个食谱?