本文整理匯總了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()