Python学习笔记(二)
来源:互联网 发布:欢乐颂2网络首播量 编辑:程序博客网 时间:2024/06/05 22:46
Mysql连接
config={ 'host' : '127.0.0.1', 'database' : 'dbname', 'user' : '', 'password' : '', 'charset' : 'utf8', 'port' : 3306, #'_connection_string' : "mysql:host=127.0.0.1;dbname=dbname;port=3306" }
@staticmethod def get_user_info(dealer_id): db = config.DBConfig.get() try: cnn = mysql.connector.connect(**db) cursor = cnn.cursor() sql_query = """SELECT id,user_name,age,gender,score FROM user_tbl WHERE user_name like %s limit 10 """ cursor.execute(sql_query,('nibushiren',)) #打印列名 column_names = cursor.column_names print("""{} {}\t{}\t{}""".format(*column_names)) index = 0 for id,user_name,age,gender in cursor: if index > 100: break print('%4d\t\t%10s\t\t%2d\t%2s\t%6.4f' % (id,user_name,age,gender,score)) index += 1 cursor.close() cnn.close() except mysql.connector.Error as e: print('connect fails!{}'.format(e))
以上是读数据库操作。
未完待续。
0 0
- python学习笔记(二)
- Python学习笔记(二)
- Python学习笔记(二)
- python学习笔记(二)
- Python学习笔记(二)
- python学习笔记(二)
- python学习笔记(二)
- Python学习笔记(二)
- python学习笔记(二)
- python学习笔记(二)
- Python学习笔记(二)
- python学习笔记:(二)
- Python学习笔记(二)
- Python学习笔记(二)
- Python学习笔记(二)
- python学习笔记(二)
- python学习笔记(二)
- Python学习笔记(二)
- HTTP协议详解 非常经典
- CRect
- sqlserver游标嵌套时@@FETCH_STATUS的值
- 00-java实现设计模式-设计模式概述
- Android Stdio 中Live Templates设置
- Python学习笔记(二)
- cookie和session
- Hadoop再探讨
- 5.销售员旅行问题:设有5个相互可直达的城市A、B、C、D、E
- Android:基于局域网的聊天系统
- RobotArt生成轨迹类型选择技巧
- 开源大数据处理工具
- jsp
- C#今天时间的开始结束,今天是周几,本周的开始和结束