【发布时间】:2013-05-10 23:34:54
【问题描述】:
通过 cli:
[root@localhost 0]# python test13.wsgi
(1, 'aaaaaa')
(2, 'sdsdfsdfsd')
(3, 'dsfsdfasdfsdf')
(4, 'sdgsdgsdfsa')
[root@localhost 0]#
通过阿帕奇:
(4, 'sdgsdgsdfsa')
脚本代码:
import MySQLdb
conn = MySQLdb.connect (host = "localhost",
user = "root",
passwd = "",
db = "aaa")
cursor = conn.cursor ()
cursor.execute ("select * from bbb limit 10")
numrows = int(cursor.rowcount)
for i in range(numrows):
row = cursor.fetchone()
print row
cursor.close ()
conn.close ()
def application(environ, start_response):
start_response('200 OK', [('content-type', 'text/html')])
return [repr(row)]
我想简单地将所有这些行放入一个数组中,如 php 然后与 php 相比,在 python 中做一个 print_r() 等价。
所以在 apache 中打印的是一切,而不仅仅是 最后一个。
【问题讨论】:
标签: python python-2.7 mod-wsgi wsgi mysql-python