您的位置:首页 > 编程语言 > Python开发

在SAE的Python工程上使用MySQL

2015-02-03 14:21 253 查看
1、首先需要在SAE中创建一个python项目,详细参考SAE官方文档

http://sae.sina.com.cn/doc/python/tutorial.html

2、在创建的项目中的MySQL中创建一个表



3、使用如下代码访问

import sae.const
import string
import MySQLdb

_host=sae.const.MYSQL_HOST
_user=sae.const.MYSQL_USER
_passwd=sae.const.MYSQL_PASS
_db=sae.const.MYSQL_DB
_charset= 'utf-8'
_port = string.atoi(sae.const.MYSQL_PORT)

import time,MySQLdb
conn = MySQLdb.connect(host= _host,port= _port,user= _user,passwd= _passwd, db=_db)
cursor = conn.cursor()

result = ""

n = cursor.execute("select * from words")
for row in cursor.fetchall():
for r in row:
result = result + str(r) + " "
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: