-
from django.db import load_backend, transaction, connection
-
-
#manipular datos de una bd externa
-
-
def sincronizeDB(self):
-
myBackend = load_backend(‘mysql’) # or ‘mysql’, ‘sqlite3’, ‘oracle’
-
myConnection = myBackend.DatabaseWrapper({
-
‘DATABASE_HOST’: ‘192.168.1.11’,
-
‘DATABASE_NAME’: ‘agenciaperu_local’,
-
‘DATABASE_OPTIONS’: {},
-
‘DATABASE_PASSWORD’: “”,
-
‘DATABASE_PORT’: “”,
-
‘DATABASE_USER’: “root”,})
-
# Now we can do all the standard raw sql stuff with myConnection.
-
myCursor = myConnection.cursor()
-
id = 22
-
name = “tecnologia para jos”
-
slug = “tecnologia_para_jos”
-
row = myCursor.execute(“INSERT INTO category(name, slug ) values(%s,%s);”, [name, slug])
-
row = myConnection._commit()
-
#row = transaction.rollback_unless_managed() —–> sería cuando trabajamos en local
-
-
# select simple
-
#row = myCursor.execute(“select *from category where id = %s and highlight = %s;”,[id,0])
-
myCursor.fetchall()