<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></title> 
<link>http://www.bizeway.net/index.php</link> 
<description><![CDATA[网务通 - 网务公司发展之路]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></copyright>
<item>
<link>http://www.bizeway.net/read.php?</link>
<title><![CDATA[跟着ArthurXF学习python2——让python可以访问mysql]]></title> 
<author>ArthurXF &lt;arthurxf@gmail.com&gt;</author>
<category><![CDATA[python]]></category>
<pubDate>Sun, 05 Oct 2008 05:13:35 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?</guid> 
<description>
<![CDATA[ 
	　　其实这个动作也很简单，只是python不像PHP那样默认支持mysql，所以我们必须为python安装一个mysql的扩展库。<br/><br/>1.首先下载<br/><a href="http://sourceforge.net/project/showfiles.php?group_id=22307&package_id=15775&release_id=491012" target="_blank">MySQL for python</a><br/>因为我们是在windows下用的，所以我下载了一个MySQL-python-1.2.2.win32-py2.5.exe<br/>2.直接执行安装，只要你已经安装过python，那么安装会相当顺利，一切默认即可完成安装了。<br/>3.加载模块<br/>如果我们执行import MySQLdb，没有报错，说明安装成功了，不过千万要注意大小写哦，很容易搞错的。<br/>4.模块中的常用函数<br/>connect()方法用于连接数据库，返回一个数据库连接对象。如果要连接一个位于host.remote.com服务器上名为fourm的MySQL数据库，连接串可以这样写：<br/><br/>db = MySQLdb.connect(host="remote.com",user="user",passwd="xxx",db="fourm" )connect()的参数列表如下：<br/><br/>host，连接的数据库服务器主机名，默认为本地主机(localhost)。<br/><br/>user，连接数据库的用户名，默认为当前用户。<br/><br/>passwd，连接密码，没有默认值。<br/><br/>db，连接的数据库名，没有默认值。<br/><br/>conv，将文字映射到Python类型的字典。默认为MySQLdb.converters.conversions<br/><br/>cursorclass，cursor()使用的种类，默认值为MySQLdb.cursors.Cursor。<br/><br/>compress，启用协议压缩功能。<br/><br/>named_pipe，在windows中，与一个命名管道相连接。<br/><br/>init_command，一旦连接建立，就为数据库服务器指定一条语句来运行。<br/><br/>read_default_file，使用指定的MySQL配置文件。<br/><br/>read_default_group，读取的默认组。<br/><br/>unix_socket，在unix中，连接使用的套接字，默认使用TCP。<br/><br/>port，指定数据库服务器的连接端口，默认是3306。<br/><br/>连接对象的db.close()方法可关闭数据库连接，并释放相关资源。<br/><br/>连接对象的db.cursor([cursorClass])方法返回一个指针对象，用于访问和操作数据库中的数据。<br/><br/>连接对象的db.begin()方法用于开始一个事务，如果数据库的AUTOCOMMIT已经开启就关闭它，直到事务调用commit()和rollback()结束。<br/><br/>连接对象的db.commit()和db.rollback()方法分别表示事务提交和回退。<br/><br/>指针对象的cursor.close()方法关闭指针并释放相关资源。<br/><br/>指针对象的cursor.execute(query[,parameters])方法执行数据库查询。<br/><br/>指针对象的cursor.fetchall()可取出指针结果集中的所有行，返回的结果集一个元组(tuples)。<br/><br/>指针对象的cursor.fetchmany([size=cursor.arraysize])从查询结果集中取出多行，我们可利用可选的参数指定取出的行数。<br/><br/>指针对象的cursor.fetchone()从查询结果集中返回下一行。<br/><br/>指针对象的cursor.arraysize属性指定由cursor.fetchmany()方法返回行的数目，影响fetchall()的性能，默认值为1。<br/><br/>指针对象的cursor.rowcount属性指出上次查询或更新所发生行数。-1表示还没开始查询或没有查询到数据。<br/>5.使用例子<br/>#!/usr/bin/python<br/>import MySQLdb<br/>try: &nbsp; <br/> &nbsp;connection = MySQLdb.connect(user="user",passwd="password",host="xxx",db="test")except: <br/> &nbsp;print "Could not connect to MySQL server." <br/> &nbsp;exit( 0 )<br/>try:<br/> &nbsp; cursor = connection.cursor() <br/> &nbsp; cursor.execute( "SELECT note_id,note_detail FROM note where note_id = 1" ) <br/> &nbsp; print "Rows selected:", cursor.rowcount <br/> &nbsp; for row in cursor.fetchall():<br/> &nbsp; &nbsp; &nbsp; print "note : ", row[0], row[1]<br/> &nbsp; cursor.close()<br/>Tags - <a href="tag.php?tag=python" rel="tag">python</a> , <a href="tag.php?tag=mysql" rel="tag">mysql</a>
]]>
</description>
</item><item>
<link>http://www.bizeway.net/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] 跟着ArthurXF学习python2——让python可以访问mysql]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>