💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 查询一行数据 * 创建testSelectOne.py文件,查询一条学生信息 ~~~ #encoding=utf8 import MySQLdb try: conn=MySQLdb.connect(host='localhost',port=3306,db='test1',user='root',passwd='mysql',charset='utf8') cur=conn.cursor() cur.execute('select * from students where id=7') result=cur.fetchone() print result cur.close() conn.close() except Exception,e: print e.message ~~~ ## 查询多行数据 * 创建testSelectMany.py文件,查询一条学生信息 ~~~ #encoding=utf8 import MySQLdb try: conn=MySQLdb.connect(host='localhost',port=3306,db='test1',user='root',passwd='mysql',charset='utf8') cur=conn.cursor() cur.execute('select * from students') result=cur.fetchall() print result cur.close() conn.close() except Exception,e: print e.message ~~~