Advanced search FAQ Register Login

It is currently Mon Jan 22, 2018 1:38 am

 

Postby Paul Vermeeren » Tue Sep 15, 2015 7:08 pm

Hi,

I am trying for a couple of days now but I can't figure out how to connect via python to my MySQL database.

My plan is to connect from a website to the raspberry pi and control the wheels.
I am trying to control the speed of the wheels via a MySQL database.

The last thing I tried is:
(I have more things imported but this is the only thing for MySQL.

Code: Select all

import MySQLdb

conn = MySQLdb.connect(database="XX",host="XX",user="XX",password="XX")

cur = conn.cursor()

cur.execute("SELECT * FROM XX")
for row in cur.fetchall() :
     PBR.SetMotor1(row[0])
     PBR.SetMotor2(row[1])

Paul Vermeeren
n00b

Posts: 8

Joined: Sun Sep 06, 2015 3:38 pm

Postby Jake » Thu Sep 17, 2015 2:12 pm

Hi Paul,

Have you installed the MySQLdb library?

sudo apt-get install python-mysqldb

Good resource on connecting MySQL via Python

http://stackoverflow.com/questions/3728 ... -in-python

-- Jake

Jake
ModMyPi

User avatar

Posts: 1396

Joined: Thu Aug 27, 2015 3:57 pm

Forum Administrator & Technical Support

Postby Aikidokajeff » Thu Sep 17, 2015 3:47 pm

Hi Paul,

Are you able to connect to MySQL via the command line and execute your queries successfully?

Jeff

Aikidokajeff
n00b

Posts: 8

Joined: Thu Aug 27, 2015 2:32 pm

Postby Paul Vermeeren » Fri Sep 18, 2015 2:42 pm

Hi,

I'm not sure if I tried via the command line but I think that it also did not work.

I had already tried that post.
But the error that most occurred was about the logging in part.

So I gave up and got it working via a text file on my website and outputted the value with PHP and then read it from the website with python.
That way is a little more complex but I got it working eventually.


Paul

Paul Vermeeren
n00b

Posts: 8

Joined: Sun Sep 06, 2015 3:38 pm

Who is online

Users browsing this forum: No registered users and 1 guest

Board index

The teamDelete all board cookies • All times are UTC [ DST ]