<ASK>create table python for mysql on xbmc
#1
how do I connect to mysql database from python in XBMC. and insert, update delete mysql table in python script? because at the time of calling a python script on XBMC have always failed script error?

import MySQLdb as mdb
import sys


def mySQLtest():
DB = 'test'
HOST = 'localhost'
DB_USER = 'root'
DB_PASSWORD = ''
conn = MySQLdb.Connection(db=test, host=DB_HOST, user=DB_USER,
passwd=DB_PASSWORD)
cursor = conn.cursor()
sql = """show tables;"""
cursor.execute(sql)
results = cursor.fetchall()
cursor.close()
conn.close()
return results
Reply
#2
Well at the start you're importing the MySQLdb as mbd so every instance afterwards needs to be called mdb instead of MySQLdb.

So your line:
Code:
conn = MySQLdb.Connection(db=test, host=DB_HOST, user=DB_USER,
passwd=DB_PASSWORD)

should be:
Code:
conn = mdb.Connection(db=test, host=DB_HOST, user=DB_USER,
passwd=DB_PASSWORD)

rushit Wrote:how do I connect to mysql database from python in XBMC. and insert, update delete mysql table in python script? because at the time of calling a python script on XBMC have always failed script error?

import MySQLdb as mdb
import sys


def mySQLtest():
DB = 'test'
HOST = 'localhost'
DB_USER = 'root'
DB_PASSWORD = ''
conn = MySQLdb.Connection(db=test, host=DB_HOST, user=DB_USER,
passwd=DB_PASSWORD)
cursor = conn.cursor()
sql = """show tables;"""
cursor.execute(sql)
results = cursor.fetchall()
cursor.close()
conn.close()
return results
Reply
#3
giftie Wrote:Well at the start you're importing the MySQLdb as mbd so every instance afterwards needs to be called mdb instead of MySQLdb.

So your line:
Code:
conn = MySQLdb.Connection(db=test, host=DB_HOST, user=DB_USER,
passwd=DB_PASSWORD)

should be:
Code:
conn = mdb.Connection(db=test, host=DB_HOST, user=DB_USER,
passwd=DB_PASSWORD)

when I check import MySQLdb, MySQLdb can not be on the call by XBMC import command, I use XBMC Live 10 dharma version. is there another way to connect other than XBMC python script? or if anyone had success connecting python to create table, insert, table, and delete tables from the XBMC to the mysql server? Can I know the simple python script for XBMC connect to the mysql server. i really need this information because i am already 1 weeks not solve the problem Confused
Reply
#4
rushit Wrote:when I check import MySQLdb, MySQLdb can not be on the call by XBMC import command, I use XBMC Live 10 dharma version. is there another way to connect other than XBMC python script? or if anyone had success connecting python to create table, insert, table, and delete tables from the XBMC to the mysql server? Can I know the simple python script for XBMC connect to the mysql server. i really need this information because i am already 1 weeks not solve the problem Confused

I believe the programmer twinther has made a script.module to access MySQL databases -- script.module.myconnpy -- check his addon out at https://github.com/twinther/script.moviequiz
Reply

Logout Mark Read Team Forum Stats Members Help
<ASK>create table python for mysql on xbmc0