- 论坛徽章:
- 1
|
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import MySQLdb as mdb
- import sys
- reload(sys)
- sys.setdefaultencoding('utf-8')
- con = mdb.connect(host='192.168.1.212',user='root',passwd='123456',port=3307,db='xy_db_community_s12',charset='utf8');
- with con:
- name=" '%ac%' "
- print name
- print type(name)
- cur = con.cursor(r'SELECT xy_tbl_guildmember.MemberName FROM xy_tbl_guildmember, xy_tbl_guild WHERE xy_tbl_guildmember.GUILD = xy_tbl_guild.GUILD AND xy_tbl_guild.GuildName LIKE %s AND xy_tbl_guildmember.GuildPos < 4;' %name)
- #cur.execute("SELECT * FROM xy_tbl_guild")
- #rows = cur.fetchall()
- #for row in rows:
- # print row
- '''
- numberrows=int(cur.rowcount)
- print numberrows
- for i in range(numberrows):
- row=cur.fetchone()
- print row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10],row[11]
- #rower=cur.fetchone()
- #print rower
- '''
- rows=cur.fetchall()
- for row in rows:
- row_list=list(row)
- print "%s" %(row_list[0])
- #print type(row)
- #print type(row_list)
复制代码 错误提示- /usr/bin/python /data/script/python/pycharm_obj_dir/python_exercise/mysql_02.py
- Traceback (most recent call last):
- '%ac%'
- File "/data/script/python/pycharm_obj_dir/python_exercise/mysql_02.py", line 17, in <module>
- <type 'str'>
- cur = con.cursor(r'SELECT xy_tbl_guildmember.MemberName FROM xy_tbl_guildmember, xy_tbl_guild WHERE xy_tbl_guildmember.GUILD = xy_tbl_guild.GUILD AND xy_tbl_guild.GuildName LIKE %s AND xy_tbl_guildmember.GuildPos < 4;' %name)
- File "build/bdist.linux-i686/egg/MySQLdb/connections.py", line 243, in cursor
- TypeError: 'str' object is not callable
- Process finished with exit code 1
复制代码 这是 什么情况~ |
|