Python & MySQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jason.massey@gmail.com

    Python & MySQL

    Hi all,

    I've got a weird problem. I was running Python 2.3 and MySQLdb and had
    everything running fine.

    Cutting to the chase: After upgrading to 2.4 (and latest modules) the
    MySQLdb functions in Python can connect to the database, do queries and
    do inserts.

    Or rather, it seems to do inserts. If I just run in the Python command
    line and manually connect to the database and do an insert and then a
    query on what I just inserted the info is there.

    However when I use SQLyog to look at the database the info isn't there.
    When I close down Python, restart, reconnect and query the info isn't
    there.

    Info inserted from SQLyog is persistant.

    Has anyone had any problems like this before?

    thanks,

    jason

  • jason.massey@gmail.com

    #2
    Re: Python & MySQL

    Okay,

    I had the brilliant idea right after posting to google the newsgroups
    on this.

    db = MySQLdb.connect (user=database_ user,passwd=dat abase_password)

    db.autocommit(T rue) <--- One little line!


    There ya go. Works like a champ. I swear I was pulling my hair out
    yesterday over this.

    Comment

    • Steve Holden

      #3
      Re: Python &amp; MySQL

      jason.massey@gm ail.com wrote:[color=blue]
      > Hi all,
      >
      > I've got a weird problem. I was running Python 2.3 and MySQLdb and had
      > everything running fine.
      >
      > Cutting to the chase: After upgrading to 2.4 (and latest modules) the
      > MySQLdb functions in Python can connect to the database, do queries and
      > do inserts.
      >
      > Or rather, it seems to do inserts. If I just run in the Python command
      > line and manually connect to the database and do an insert and then a
      > query on what I just inserted the info is there.
      >
      > However when I use SQLyog to look at the database the info isn't there.
      > When I close down Python, restart, reconnect and query the info isn't
      > there.
      >
      > Info inserted from SQLyog is persistant.
      >
      > Has anyone had any problems like this before?
      >
      > thanks,
      >
      > jason
      >[/color]
      I suspect you are forgetting to commit your changes to the database, so
      they are being rolled back when you close your connection.

      regards
      Steve
      --
      Steve Holden +1 703 861 4237 +1 800 494 3119
      Holden Web LLC http://www.holdenweb.com/
      Python Web Programming http://pydish.holdenweb.com/

      Comment

      • Steve Holden

        #4
        Re: Python &amp; MySQL

        jason.massey@gm ail.com wrote:[color=blue]
        > Hi all,
        >
        > I've got a weird problem. I was running Python 2.3 and MySQLdb and had
        > everything running fine.
        >
        > Cutting to the chase: After upgrading to 2.4 (and latest modules) the
        > MySQLdb functions in Python can connect to the database, do queries and
        > do inserts.
        >
        > Or rather, it seems to do inserts. If I just run in the Python command
        > line and manually connect to the database and do an insert and then a
        > query on what I just inserted the info is there.
        >
        > However when I use SQLyog to look at the database the info isn't there.
        > When I close down Python, restart, reconnect and query the info isn't
        > there.
        >
        > Info inserted from SQLyog is persistant.
        >
        > Has anyone had any problems like this before?
        >
        > thanks,
        >
        > jason
        >[/color]
        I suspect you are forgetting to commit your changes to the database, so
        they are being rolled back when you close your connection.

        regards
        Steve
        --
        Steve Holden +1 703 861 4237 +1 800 494 3119
        Holden Web LLC http://www.holdenweb.com/
        Python Web Programming http://pydish.holdenweb.com/

        Comment

        Working...