質問
import _mysql as mysql
db=mysql.connect('localhost','username','password','database')
db.query("""select * from news""")
result = db.store_result()
print result.num_rows()#two records
#how to loop? without cursor
print result.fetch_row()
他のヒント
輸入してはいけません _mysql
. 。単一のアンダースコアで始まるシンボルは、プライベートで使用するためです。輸入 MySQLdb
そして読んでください PEP 249 その使用のために。
ループの使用方法がわかりませんが、このようなことをすることができます。
while x < result.num_rows():
#do something for each row
X += 1
所属していません StackOverflow