开发者

equivalent connection for postgres and sqlite

Is there an equivalent way to connect to a postgres database in a similar way that sqlite connects to a database using python?

For example, in sqlite, a conne开发者_如何学编程ction will be defined by conn = sqlite3.connect(curruser.dbname). What is the similar connection syntax for postgres?


You can use the psycopg connector then, and the connection syntax will be similar, except that you'll need to specify some more information in a connection string:

conn_string = "host='localhost' dbname='my_database' user='postgres' password='secret'"
conn = psycopg2.connect(conn_string)

Here are some examples: Using psycopg2 with PostgreSQL

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜