本文整理汇总了Python中_mysql.connect方法的典型用法代码示例。如果您正苦于以下问题:Python _mysql.connect方法的具体用法?Python _mysql.connect怎么用?Python _mysql.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_mysql
的用法示例。
在下文中一共展示了_mysql.connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: data_from_mysql
# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connect [as 别名]
def data_from_mysql(itempath):
#?????cursor
try:
#???mysql??? ???? ??? ?? ????
connect_mysql = mysql.connect("localhost","judgetest","123456","judgedoctest")
with connect_mysql:
cur = connect_mysql.cursor()
for item in filePath:
readfile = open(item).read()
#print(readfile)
iditem =
except mysql.Error,e:
print("mysql Error ")
connect_mysql.close()
示例2: main
# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connect [as 别名]
def main():
db=_mysql.connect("localhost","nibrahim","foo","sample")
print "Digraph F {\n"
print 'ranksep=1.5; size = "17.5,7.5";rankdir=LR;'
for i in get_tables(db):
writedeps(db, i)
print "}"
示例3: connect
# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connect [as 别名]
def connect(self):
client = None
try:
client = MySQLdb.connect(
host=self.host, port=self.port, user=self.user,
passwd=self.password, db=self.database, connect_timeout=5,
cursorclass=MySQLdb.cursors.DictCursor, compress=1
)
yield client
finally:
if client:
client.close()
示例4: execute
# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connect [as 别名]
def execute(self, sql_statement):
with self.connect() as client:
client.query(sql_statement)
result = client.store_result()
if result:
return result.fetch_row(maxrows=0, how=1)
示例5: query
# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connect [as 别名]
def query(self, sql_statement):
with self.connect() as client:
client.query(sql_statement)
client.commit()
示例6: checkUpdate
# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connect [as 别名]
def checkUpdate(self):
self.log.f("pa", "Searching for entries...")
conn = pymysql.connect(self.config.get("mysql")["hostname"],
self.config.get("mysql")["username"],
self.config.get("mysql")["password"],
self.config.get("mysql")["database"])
cursor = conn.cursor()
find_entry = ("SELECT entryid, author, content, used, approved " +
"FROM questions WHERE approved = 1 AND used = 0")
cursor.execute(find_entry)
data = cursor.fetchall()
if len(data) == 0:
self.log.f("pa", "Could not find suitable entry")
else:
askrow = data[random.randint(0, len(data) - 1)]
em = discord.Embed(title="Patch Asks",
description="Today Patch asks: \n "
+ askrow[2],
colour=0x0acdff)
msg = await self.client.embed(self.client.get_channel(
self.config.get
("mysql")["channelid"]), em)
await self.client.send_message(msg.channel,
"*today's patch asks was " +
"written by " + askrow[1]
.strip() + "*")
self.log.f("pa", "Going with entry: " + str(askrow[0]) + " by "
+ askrow[1].strip())
try:
mark_entry = ("UPDATE questions SET used = 1 WHERE " +
"entryid={}".format(askrow[0]))
cursor.execute(mark_entry)
conn.commit()
except:
self.log.err("An SQL error occurred")
conn.rollback()
finally:
conn.close()