当前位置: 首页>>代码示例>>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;未经允许,请勿转载。