程序员人生 网站导航

Python MySql 数据库操作

栏目:互联网时间:2014-10-12 18:59:39
# -*- coding: utf-8 -*- # mysqlTest.py import mysql.connector conn = mysql.connector.connect(user='root',host='127.0.0.1', port='3306', password='admin', database='test_db', use_unicode=True) cursor = conn.cursor() # cursor.execute('insert into table_test(id, name) values(%s, %s)', ['4', 'hello wangwei']) # cursor.rowcount # conn.commit() # cursor.close() cursor = conn.cursor() cursor.execute('select * from table_test') values = cursor.fetchall() print values cursor.close() conn.close()

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐