必威电竞|足球世界杯竞猜平台

MySQLdb
來源:互聯網

MySQL是一個小型關系型數據庫管理系統,開發者為瑞典MySQL AB公司。在2008年1月16號被太陽微系統收購。目前MySQL被廣泛地應用在Internet上的中小型網站中。由于其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點,許多中小型網站為了降低網站總體擁有成本而選擇了MySQL作為網站數據庫。

簡介

MySQLdb

Python 連接 MySQL 的模塊。 MySQL versions 3.23-5.1; and Python versions 2.3-2.5 are supported.

Python

Python是一種編程語言,它的名字來源于一個喜劇。也許最初設計Python這種語言的人并沒有想到今天Python會在工業和科研上獲得如此廣泛的使用。著名的自由軟件作者EricRaymond在他的文章《如何成為一名黑客》中,將Python列為黑客應當學習的四種編程語言之一,并建議人們從Python開始學習編程。這的確是一個中肯的建議,對于那些從來沒有學習過編程或者并非計算機專業的編程學習者而言,Python是最好的選擇之一。Python第一次學習Python,我只用了不到二十分鐘的時間,站在書店里把一本教初學編程的人學習Python的書翻了一遍。也是從那時起,我開始被這種神奇的語言吸引。

屬性和方法

控制資料公司

BINARY = DBAPISet([249, 250, 251, 252])

DATE = DBAPISet([10, 14])

NULL = 'NULL'

NUMBER = DBAPISet([0, 1, 3, 4, 5, 8, 9, 13])

ROWID = DBAPISet([])

STRING = DBAPISet([253, 254, 247])

時間 = DBAPISet()

TIMESTAMP = DBAPISet([12, 7])

__all__ = ['BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date'...

__author__ = '安德魯 dustman __revision__ = '491'

__version__ = '1.2.2'

__warningregistry__ = {('the sets module is deprecated',

apilevel = '2.0'

paramstyle = 'format'

threadsafety = 1

version_info = (1, 2, 2, 'final', 0)

FUNCTIONS

Binary(x)

Connect(*args, **kwargs)

Factory function for connections.Connection.

Connection = Connect(*args, **kwargs)

Factory function for connections.Connection.

DateFromTicks(ticks)

Convert unix ticks into a date instance.

TimeFromTicks(ticks)

Convert UNIX ticks into a 時間 instance.

TimestampFromTicks(ticks)

Convert UNIX ticks into a datetime instance.

connect = Connect(*args, **kwargs)

Factory function for connections.Connection.

debug(...)

DOES a DBUG_PUSH with the given string.

MySQL_debug() uses the Fred Fish debug library.

To use this function, you must compile the client library to

support debugging.

escape(...)

escape(obj, dict) -- escape any special characters in object obj

using mapping dict to provide quoting functions for each type.

Returns a SQL literal string.

escape_dict(...)

escape_sequence(d, dict) -- escape any special characters in

dictionary d using mapping dict to provide quoting functions for each type.

Returns a dictionary of escaped items.

escape_sequence(...)

escape_sequence(seq, dict) -- escape any special characters in sequence

seq using mapping dict to provide quoting functions for each type.

Returns a tuple of escaped items.

escape_string(...)

escape_string(s) -- quote any SQLinterpreted characters in string s.

Use connection.escape_string(s), if you use it at all.

_mysql.escape_string(s) cannot handle character sets. You are

probably better off using connection.escape(o) instead, since

it will escape entire sequences as well as strings.

get_client_info(...)

get_client_info() -- Returns a string that represents

the client library version.

string_literal(...)

string_literal(obj) -- converts object obj into a SQL string literal.

This means, any special SQL characters are escaped, and it is enclosed

within single quotes. In other words, it performs:

"'%s'" % escape_string(str(obj))

簡單使用

>>>import MySQLdb

>>>test=MySQLdb.connect(db='databasename',host='localhost',user='username',passwd='password')

>>> cur = test.cursor()

>>> cur.execute('CREATE TABLE USERS(login VARCHAR(8), uid INT)')

0L

現在我們來插入幾行數據到數據庫, 然后再將它們取出來.

>>> cur.execute("INSERT INTO users VALUES('john', 7000)")

1L

>>> cur.execute("INSERT INTO users VALUES('jane', 7001)")

1L

>>> cur.execute("INSERT INTO users VALUES('bob', 7200)")

1L

>>> cur.execute("SELECT * FROM users WHERE login LIKE 'j%'")

2L

>>> for data in cur.fetchall():

... print '%s\t%s' % data

...

john 7000

Jane 7001

更多幫助

更多內容參見Python在線幫助文檔

>>>help()

help>MySQLdb

參考資料 >

生活家百科家居網