• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python python_mysql_dbconfig.read_db_config函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中python_mysql_dbconfig.read_db_config函数的典型用法代码示例。如果您正苦于以下问题:Python read_db_config函数的具体用法?Python read_db_config怎么用?Python read_db_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了read_db_config函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create_user

def create_user():
	print ('create')
	data = request.json	
	browser = data['browser']
	ip = data['ip']
			
	query = "SELECT COUNT(*) FROM users WHERE browser = %s AND ip = %s"
	try:		
		dbconfig = read_db_config()
		conn = MySQLConnection(**dbconfig)
		cursor = conn.cursor()
		cursor.execute(query, (browser, ip),)
		count = cursor.fetchone()
		count = count[0]
	except Error as e:
		print(e)
	finally:
		cursor.close()
		conn.close()
	if count != 0:
		query = "SELECT id FROM users WHERE browser = %s AND ip = %s"
		try:		
			dbconfig = read_db_config()
			conn = MySQLConnection(**dbconfig)
			cursor = conn.cursor()
			cursor.execute(query, (browser, ip),)
			id = cursor.fetchone()
		except Error as e:
			print(e)
		finally:
			cursor.close()
			conn.close()
		#if user already exist return his id
		return jsonify({'state': 'fail', 'index' : id}) 
	
	#if user is not exist add him to db
	query = "INSERT INTO users (date, browser, ip) VALUES (%s, %s, %s)"    
	date = datetime.now()
	try:
		db_config = read_db_config()
		conn = MySQLConnection(**db_config)
		cursor = conn.cursor()
		cursor.execute(query, (date, browser, ip, ),)
		conn.commit()
	except Error as error:
		print(error)
	finally:
		cursor.close()
		conn.close()				
	return jsonify({'state': 'OK'})
开发者ID:navigator3228,项目名称:netlabs,代码行数:50,代码来源:server.py


示例2: insert_user

def insert_user(name, password, email):
    query = "INSERT INTO users(username, password, email) " \
            "VALUES(%s,%s,%s)"

    args = (name, password, email)
 
    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)
 
        cursor = conn.cursor()
        cursor.execute(query, args)
 
        if cursor.lastrowid:
            print('last insert id', cursor.lastrowid)
        else:
            print('last insert id not found')
 
        conn.commit()
    except Error as error:
        print(error)
 
    finally:
        cursor.close()
        conn.close()
开发者ID:yxnely,项目名称:practice-flask,代码行数:25,代码来源:python_mysql_dbinsert.py


示例3: insert_book

def insert_book(title, isbn):
    query = "INSERT INTO books(title, isbn) " "VALUES(%s, %s)"

    args = (title, isbn)

    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)

        cursor = conn.cursor()
        cursor.execute(query, args)

        if cursor.lastrowid:
            print ("last insert id", cursor.lastrowid)
        else:
            print ("last insert id not found")

        conn.commit()

    except Error as error:
        print error

    finally:
        cursor.close()
        conn.close()
开发者ID:Angadlamba,项目名称:comicBio,代码行数:25,代码来源:python_mysql_insert.py


示例4: update_book

def update_book(book_id, title):
    # read database configuration
    db_config = read_db_config()
 
    # prepare query and data
    query = """ UPDATE books
                SET title = %s
                WHERE id = %s """
 
    data = (title, book_id)
 
    try:
        conn = MySQLConnection(**db_config)
 
        # update book title
        cursor = conn.cursor()
        cursor.execute(query, data)
 
        # accept the changes
        conn.commit()
 
    except Error as error:
        print(error)
 
    finally:
        cursor.close()
        conn.close()
开发者ID:DanielAvelar,项目名称:Python,代码行数:27,代码来源:query_update_one_row.py


示例5: insert_name

def insert_name(name, gender):
    query = "INSERT INTO babynames(babyName, gender) " \
            "VALUES(%s,%s)"

    args = (name, gender)
 
    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)
 
        cursor = conn.cursor()
        cursor.execute(query, args)
 
        if cursor.lastrowid:
            print('last insert id', cursor.lastrowid)
        else:
            print('last insert id not found')
 
        conn.commit()
    except Error as error:
        print(error)
 
    finally:
        cursor.close()
        conn.close()
开发者ID:yxnely,项目名称:practice-flask,代码行数:25,代码来源:python_mysql_dbinsert2.py


示例6: login_page

def login_page():
    error = ''
    gc.collect()
    try:
        dbconfig = read_db_config()
        conn = MySQLConnection(**dbconfig)
        cur = conn.cursor()
        if request.method == "POST":
            query = ("""SELECT * FROM users WHERE username = %s""")
            cur.execute(query, (request.form['username'],))
            userpw = cur.fetchone()[2]

            if sha256_crypt.verify(request.form['password'], userpw):
                session['logged_in'] = True
                session['username'] = request.form['username']
                session['user-ip'] = request.remote_addr
                if session['username'] == 'admin':
                    flash(Markup('The Dark Knight&nbsp;&nbsp;<span class="glyphicon glyphicon-knight"></span>'))
                else:
                    flash('Logged In')
                return redirect(url_for('blog'))
            else:
                error = "Invalid Credentials. Please try again."

        gc.collect()

        return render_template('login.html', error = error)

    except Exception as e:
        error = 'Invalid Credentials. Please try again.'
        return render_template('login.html', error = error)
开发者ID:dawoudt,项目名称:dawoudt.com,代码行数:31,代码来源:__init__.py


示例7: insert_imei

def insert_imei(query, args):

    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)

        cursor = conn.cursor()
        cursor.execute(query, args)

        if cursor.lastrowid:
            mensaje = ('Last insert id: %s' % (cursor.lastrowid,) )
            print(mensaje)
        else:
           mensaje = 'Last insert id not found'

        conn.commit()
        
    
    except Error as error:
        print(error)

    finally:
        cursor.close()
        conn.close()
        
    return mensaje    
开发者ID:richpolis,项目名称:ServerAndClient,代码行数:26,代码来源:insert_imei.py


示例8: input_data

def input_data():

    for x in range(len(gabungan)):
        gabungan[x]

    query = "INSERT INTO data_test " 
    nilai = "VALUES (\"\"," + "\"" + file + "\"" + ","
    for x in range(len(gabungan)):
        nilai = nilai + str(gabungan[x])
        if x < len(gabungan)-1 :
            nilai = nilai + ", " 
            
    query = query + nilai + ")"
#    print query
        
    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)
 
        cursor = conn.cursor()
        cursor.execute(query)
 
        conn.commit()
    except Error as e:
        print('Error:', e)
 
    finally:
        cursor.close()
        conn.close() 
开发者ID:bubgum,项目名称:image-processing,代码行数:29,代码来源:kombinasi.py


示例9: insert_character

def insert_character(char_id, name, realname, gender, origin, image, siteurl, deck):
	query = "INSERT INTO characters(id, name, realname, gender, origin, image, siteurl, deck) " \
			"VALUES(%s, %s, %s, %s, %s, %s, %s, %s)"  

	args = (char_id, name, realname, gender, origin, image, siteurl, deck)

	try:
		db_config = read_db_config()
		conn = MySQLConnection(**db_config)

		cursor = conn.cursor()
		cursor.execute(query, args)
		
		if cursor.lastrowid:
			print('last insert id', cursor.lastrowid)
		else:
			print('last insert id not found')

		conn.commit()

	except Error as error:
		print error

	finally:
		cursor.close()
		conn.close()
开发者ID:Angadlamba,项目名称:comicBio,代码行数:26,代码来源:character_insert.py


示例10: __init__

    def __init__(self):
        self.current_job_id = 0
        self.current_job_count = 0
        self.job_list = dict()
        self.node_list = dict()
        self.section_list = dict()
        self.acc_type_list = dict() # <acc_name:acc_bw>
        self.node_list = dict() # <node_ip: PowerNode>
        self.job_list = dict()

        self.dbconfig = read_db_config()
        self.conn = MySQLConnection(**self.dbconfig)
开发者ID:xiansl,项目名称:mytests,代码行数:12,代码来源:python_scheduler.py


示例11: __init__

 def __init__(self, fpga_node_num, total_node_num):
     self.dbconfig = read_db_config()
     self.conn = MySQLConnection(**self.dbconfig)
     self.acc_type_list = dict()
     self.total_node_num = total_node_num
     self.fpga_node_num = fpga_node_num
     self.each_section_num = 4
     self.acc_type_list[0] = ('1','acc0','EC','1200','1')
     self.acc_type_list[1] = ('2','acc1','AES','1700','1')
     self.acc_type_list[2] = ('3','acc2','FFT','1200','1')
     self.acc_type_list[3] = ('4','acc3','DTW','1200','1')
     self.acc_type_list[4] = ('5','acc4','SHA','150','0')
     self.acc_type_num = len(self.acc_type_list)
开发者ID:zhuangdizhu,项目名称:simulator,代码行数:13,代码来源:set_system.py


示例12: post

    def post(self):
        try:
            
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()
            cursor.callproc('sp_insertmember')

        except Error as e :
            return {'error': str(e)}
        finally:
            cursor.close()
            conn.close()
开发者ID:adriancherng,项目名称:EMBAmeetup,代码行数:13,代码来源:app.py


示例13: read_db

def read_db():
    try:
        dbconfig = read_db_config()
        conn = MySQLConnection(**dbconfig)
        cursor = conn.cursor()
        cursor.execute("SELECT * FROM temperature;")
        row = cursor.fetchone()
        while row is not None:
            print(row)
            row = cursor.fetchone()
    finally:
        cursor.close()
        conn.close()
开发者ID:fgjhhkfk,项目名称:Python_playground,代码行数:13,代码来源:test_db.py


示例14: search

def search():
    try:
        dbconfig = read_db_config()
        conn = MySQLConnection(**dbconfig)
        cursor = conn.cursor()
        cursor.execute("SELECT * FROM data_train")
        #row_train = cursor.fetchone()
        data_train =  list(cursor)
            
        cursor = conn.cursor()
        cursor.execute("SELECT * FROM data_test")
        data_test = list(cursor)
        
        
        index1 = 0
        for x in range(len(data_train)) :
        
            canbera = 0
            index2 = 2
            
            for y in range(82):                
                temp1 = (data_test[0][index2] - data_train[index1][index2]) 
                temp2 = (data_test[0][index2] + data_train[index1][index2])

                #print "temp1 "+str(temp1)
                #print "temp2 "+str(temp2)
                                
                if temp2 == 0 :
                    hasil_temp = abs(temp1)
                else :
                    hasil_temp = float(abs(temp1)) / float(temp2)
                
                #print "hasil temp = " + str(hasil_temp)
                canbera = float(canbera) + float(hasil_temp)
                
                index2 += 1
            index1+=1
            
            print canbera
        
            
        #for x in range(len(gabungan)):
            #row_train[x]
        
 
    except Error as e:
        print(e)
 
    finally:
        cursor.close()
        conn.close()
开发者ID:bubgum,项目名称:image-processing,代码行数:51,代码来源:kombinasi.py


示例15: __init__

    def __init__(self, scheduling_algorithm):
        self.scheduling_algorithm = scheduling_algorithm
        self.current_job_count = 0
        self.job_list = dict()
        self.node_list = dict()
        self.section_list = dict()
        self.acc_type_list = dict() # <acc_name:acc_bw>
        self.node_list = dict() # <node_ip: PowerNode>
        self.job_list = dict()
        self.job_waiting_list = dict()#<job_id: weight> could be arrival time, execution time, etc;

	self.epoch_time = time.time()
        self.dbconfig = read_db_config()
        self.conn = MySQLConnection(**self.dbconfig)
开发者ID:xiansl,项目名称:mytests,代码行数:14,代码来源:new_scheduler.py


示例16: insert_many

def insert_many(entry):
    query = "insert into test(name, class, skills) values(%s, %s, %s)"
    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)

        cursor = conn.cursor()
        cursor.executemany(query, entry)
        conn.commit()
    except Error as e:
        print "[SOMETHING BAD HAPPEND!]",e
    finally:
        cursor.close()
        conn.close()
开发者ID:saqibmubarak,项目名称:Python_Workshop,代码行数:14,代码来源:mysql_insert.py


示例17: get_users_one_month

def get_users_one_month():
	count = 0
	try:
		dbconfig = read_db_config()
		conn = MySQLConnection(**dbconfig)
		cursor = conn.cursor()
		cursor.execute("SELECT COUNT(*) FROM users")
		count = cursor.fetchone()
	except Error as e:
		print(e)
	finally:
		cursor.close()
		conn.close()
	count = count[0]
	return jsonify({'count': count})
开发者ID:navigator3228,项目名称:netlabs,代码行数:15,代码来源:server.py


示例18: update_user

def update_user(user_id):
	db_config = read_db_config()
	query = "UPDATE users SET date = %s WHERE id = %s"
	date = datetime.now()
	try:
		conn = MySQLConnection(**db_config)
		cursor = conn.cursor()
		cursor.execute(query, (date, user_id,),)
		conn.commit()
	except Error as error:
		print(error)
	finally:
		cursor.close()
		conn.close()
	return jsonify({'update': 'OK'})
开发者ID:navigator3228,项目名称:netlabs,代码行数:15,代码来源:server.py


示例19: __init__

 def __init__(self, mean):
     self.dbconfig = read_db_config()
     self.conn = MySQLConnection(**self.dbconfig)
     self.acc_type_list = ['acc0','acc1','acc2','acc3','acc4']
     self.job_size_list = ['1','1','0.3','0.5','2']
     self.job_node_list = list()
     self.fpga_available_node_list = list()
     self.fpga_non_available_node_list = list()
     self.acc_bw_list = dict()
     self.poisson_interval_mean = mean
     self.exponential_interval_mean = mean
     for acc_id in self.acc_type_list:
         self.acc_bw_list[acc_id] = '1.2'
         if acc_id == 'acc4':
             self.acc_bw_list[acc_id] = '0.15'
开发者ID:xiansl,项目名称:mytests,代码行数:15,代码来源:set-job-mysql.py


示例20: query_with_fetchmany

def query_with_fetchmany():
	print "FetchMany...........\n"
	try:
		db_config = read_db_config()
		conn  = MySQLConnection(**db_config)
		cursor = conn.cursor()
		cursor.execute('select * from test')

		for row in iter_rows(cursor, 10):
			print row
	except Error as e:
		print "[SOMETHING BAD HAPPEND ]", e
	finally:
		conn.close()
		cursor.close()
开发者ID:saqibmubarak,项目名称:Python_Workshop,代码行数:15,代码来源:python_mysql_query.py



注:本文中的python_mysql_dbconfig.read_db_config函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python python_qt_binding.loadUi函数代码示例发布时间:2022-05-27
下一篇:
Python python_digest.validate_nonce函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap