Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Python/DataBase

From ZeroWiki

Mysql

사용법

  • 아래 소스는 파이썬 DB API Spec 2.0 에 있는 것들을 사용해서 작성함(즉 다른 모듈에서도 동일하게 사용가능)
  • connect 에

host - hostname (NULL : default) user - username (NULL) passwd - password (no password) db - database name (NULL) port - integer, TCP/IP port unix_socket - TCP를 사용할 unix소켓의 위치 client_flag - integer, 필요할 경우 사용하기 위한 flag (0) 을 인자로 넣을 수 있다.

import MySQLdb
con =MySQLdb.connect(user="name", passwd="password", db="databasename")
cur = con.cursor()
cur.execute("select * from owiki_page_name")
print cur.description
print cur.rowcount
res = cur.fetchone()
res = cur.fetchall()
res = cur.fetchmany(10)
print res[x][x]
cur.close()

참고

zeropage 에서 파이선 공부할 사람은 필요한 모듈있으면 게시판에 올리기 바람. - [eternalbleu]