# -*- coding:utf-8 -*- import MySQLdb # DB に接続 db = MySQLdb.connect(user="user", passwd="password", db="test", charset="utf8") # SELECT db.query("SELECT * FROM score") result = db.store_result() # 表示 num = result.num_rows() for row in result.fetch_row(num): print row # INSERT q = "INSERT INTO `test`.`score` (`id`, `user_id`, `score`)" q += " VALUES (NULL, '1', '97');" print "%s" % (q) db.query(q) # データ挿入後は commit db.commit() # Close db.close()
0 件のコメント:
コメントを投稿