Code to connect mysql through python

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 1
Reputation: krishnasaradhi is an unknown quantity at this point 
Solved Threads: 0
krishnasaradhi krishnasaradhi is offline Offline
Newbie Poster

Code to connect mysql through python

 
0
  #1
Apr 20th, 2008
hi,

i need the code to connect mysql through python programming language
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Code to connect mysql through python

 
0
  #2
Apr 20th, 2008
You'll need an interface module:

http://wiki.python.org/moin/DatabaseInterfaces

Pick your fave

Jeff
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 311
Reputation: BearofNH is on a distinguished road 
Solved Threads: 40
BearofNH's Avatar
BearofNH BearofNH is offline Offline
Posting Whiz

Re: Code to connect mysql through python

 
0
  #3
Apr 21st, 2008
Here's an example to get you started.
  1. import MySQLdb
  2.  
  3. conn = MySQLdb.connect (host = "nephews", user = "huey", passwd = "dewey", db = "louie")
  4. cursor = conn.cursor ()
  5. table_name = "kumquat"
  6.  
  7. nlines = cursor.execute ("DROP TABLE IF EXISTS " + table_name)
  8. for x in range(nlines):
  9. print cursor.fetchone ()
  10. cursor.close ()
  11.  
  12. tdesc = "CREATE TABLE " + table_name + "("
  13. tdesc = tdesc + "IDseq INT(7) UNSIGNED,"
  14. tdesc = tdesc + "Protocol VARCHAR(8), "
  15. tdesc = tdesc + "Function VARCHAR(8), "
  16. tdesc = tdesc + "Threads INT(10) UNSIGNED, "
  17. tdesc = tdesc + "Speed DECIMAL(10,3) "
  18. tdesc = tdesc + ")"
  19. cursor = conn.cursor ()
  20. nlines = cursor.execute (tdesc)
  21. for x in range(nlines):
  22. print cursor.fetchone ()
  23. cursor.close ()
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC