2011-12-23 549 views

回答

1

我有一個快速瀏覽一下文檔:

的Django/DB文檔https://docs.djangoproject.com/en/dev/topics/db/sql/

對象django.db.connection表示默認的數據庫連接,django.db.transaction表示默認數據庫事務。要使用數據庫連接,請調用connection.cursor()以獲取遊標對象。然後,調用cursor.execute(sql,[params])來執行SQL,並使用cursor.fetchone()或cursor.fetchall()返回結果行。

和MySQL/Python文檔:http://www.tutorialspoint.com/python/python_database_access.htm

提交執行查詢後:

# Prepare SQL query to DELETE required records 
sql = "delete from mytable where id =10" 
try: 
    # Execute the SQL command 
    cursor.execute(sql) 
    # Commit your changes in the database 
    db.commit() 
except: 
    # Rollback in case there is any error 
    db.rollback() 

我希望這有助於。