python Python数据库(DB)API模板

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python数据库(DB)API模板相关的知识,希望对你有一定的参考价值。

import psycopg2

conn =  psycopg2.connect("dbname=<input_database_name>")
c = conn.cursor()
c.execute('Input Query Here')

# If you are fetching results (returns a list of tuples)
result_list = c.fetchall()

# If you are modifying the database:
conn.commit()

conn.close()

以上是关于python Python数据库(DB)API模板的主要内容,如果未能解决你的问题,请参考以下文章