请输入您要查询的百科知识:

 

词条 MySQLdb
释义

MySQL是一个小型关系型数据库管理系统,开发者为瑞典MySQLAB公司。在2008年1月16号被Sun公司收购。目前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的书翻了一遍。也是从那时起,我开始被这种神奇的语言吸引。

属性和方法

DATA

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])

TIME = DBAPISet([11])

TIMESTAMP = DBAPISet([12, 7])

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

__author__ = 'Andy Dustman __revision__ = '491'

__version__ = '1.2.2'

__warningregistry__ = {('the sets module is deprecated', <type 'except...

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 time 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 SQL-interpreted 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

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2024/12/23 19:33:08