當前位置: 首頁>>代碼示例>>Python>>正文


Python _mysql.connect方法代碼示例

本文整理匯總了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() 
開發者ID:hankSantford,項目名稱:parse_legalfile,代碼行數:18,代碼來源:judgeDocMysqlInput.py

示例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 "}" 
開發者ID:ActiveState,項目名稱:code,代碼行數:9,代碼來源:recipe-577298.py

示例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() 
開發者ID:globocom,項目名稱:FoxHA,代碼行數:14,代碼來源:connection.py

示例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) 
開發者ID:globocom,項目名稱:FoxHA,代碼行數:8,代碼來源:connection.py

示例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() 
開發者ID:globocom,項目名稱:FoxHA,代碼行數:6,代碼來源:connection.py

示例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() 
開發者ID:hdmifish,項目名稱:petal,代碼行數:44,代碼來源:commands.py


注:本文中的_mysql.connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。