如何使用 mysql、postgresql 或其他 SQL 数据库(Python 内置支持的数据库除外)?
def example():
con= Mysql("root", blablabla)
con->query("SELECT * bla bla bla")
....
最佳答案
您使用什么数据库和什么扩展?对于 sqlite3
(以及与 DB-API 2.0 兼容的任何其他扩展),您可以使用类似 this 的内容。 :
conn = sqlite3.connect('/tmp/example')
c = conn.cursor()
# Create table
c.execute('''create table stocks(date text, trans text, symbol text, qty real, price real)''')
# Insert a row of data
c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""")
# Save (commit) the changes
conn.commit()
# We can also close the cursor if we are done with it
c.close()
顺便说一句,Python 中没有 ->
关于python - Python 3.0 中的 SQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3735948/