python mysql

时间:2017-03-18 13:41:23 阅读:413次
python mysql

#!/usr/bin/python

# -*- coding: utf-8 -*-


import MySQLdb as mdb

import sys


con = None

try:

    con = mdb.connect('127.0.0.1','root', 'root', 'db');

    cur = con.cursor(mdb.cursors.DictCursor)

    cur.execute("insert into `wp`(hhh)values('jjj')")

    con.commit();

    cur.execute('select * from wp')

    rows = cur.fetchall()

    for row in rows:

        print row

except mdb.Error, e:

    print "Error %d: %s" % (e.args[0],e.args[1])

    sys.exit(1)

finally:

    if con:

        con.close()


扫描二维码关注程序员爱笔记,接收更多资讯

评论

快速评论