📜  如何将字符串变量插入 sqlite 数据库 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:04:51.601000             🧑  作者: Mango

代码示例1
def create_db():
    with con:
        cur = con.cursor()
        cur.execute("DROP TABLE IF EXISTS Contacts")
        cur.execute("CREATE TABLE Contacts (First Name TEXT, Last Name TEXT, Phone TEXT, Email TEXT);")
        cur.execute("INSERT INTO Contacts VALUES (?, ?, ?, ?);", (firstname, lastname, phone, email))

        ## call commit on the connection...
        con.commit()