MySQLdb

Discussion in 'Python' started by pavloutefkros@gmail.com, Jan 29, 2008.

  1. Guest

    hello,
    i have problem manipulating mySQL data. When i add values in a Table,
    i can recieve them instantly but when i check the table from another
    script, the new values dont exist.

    i'm not experienced in sql dbses so the problem might be something
    outside python.

    example (i do this to add values, and then i check and values have
    been added):

    ####################################################################
    import MySQLdb
    conn = MySQLdb.connect (host = 'localhost',
    user = 'root',
    passwd = 'MYPASHERE',
    db = 'test')
    cursor = conn.cursor ()

    cursor.execute ("""
    INSERT INTO testsignin (user, pass, secretcode)
    VALUES
    ('dkiauser', 'dkiapass', 'dkiacode'),
    ('gmtuser', 'gmtpass', 'gmtcode')
    """)

    print "Number of rows inserted: %d" % cursor.rowcount

    cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
    row = cursor.fetchone()
    print row
    ####################################################################

    but then when i try to get them from another script with this:

    ####################################################################
    import MySQLdb
    conn = MySQLdb.connect (host = 'localhost',
    user = 'root',
    passwd = 'MYPASHERE',
    db = 'test')
    cursor = conn.cursor ()

    cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
    row = cursor.fetchone()
    print row
    ####################################################################

    i get a None
     
    , Jan 29, 2008
    #1
    1. Advertising

  2. wrote:

    > hello,
    > i have problem manipulating mySQL data. When i add values in a Table,
    > i can recieve them instantly but when i check the table from another
    > script, the new values dont exist.
    >
    > i'm not experienced in sql dbses so the problem might be something
    > outside python.
    >
    > example (i do this to add values, and then i check and values have
    > been added):
    >
    > ####################################################################
    > import MySQLdb
    > conn = MySQLdb.connect (host = 'localhost',
    > user = 'root',
    > passwd = 'MYPASHERE',
    > db = 'test')
    > cursor = conn.cursor ()
    >
    > cursor.execute ("""
    > INSERT INTO testsignin (user, pass, secretcode)
    > VALUES
    > ('dkiauser', 'dkiapass', 'dkiacode'),
    > ('gmtuser', 'gmtpass', 'gmtcode')
    > """)
    >
    > print "Number of rows inserted: %d" % cursor.rowcount
    >
    > cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
    > row = cursor.fetchone()
    > print row
    > ####################################################################
    >
    > but then when i try to get them from another script with this:
    >
    > ####################################################################
    > import MySQLdb
    > conn = MySQLdb.connect (host = 'localhost',
    > user = 'root',
    > passwd = 'MYPASHERE',
    > db = 'test')
    > cursor = conn.cursor ()
    >
    > cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
    > row = cursor.fetchone()
    > print row
    > ####################################################################
    >
    > i get a None


    You need to commit your changes, using

    conn.commit()

    after doing them.

    Diez
     
    Diez B. Roggisch, Jan 29, 2008
    #2
    1. Advertising

  3. Tim Chase Guest

    > i have problem manipulating mySQL data. When i add values in a Table,
    > i can recieve them instantly but when i check the table from another
    > script, the new values dont exist.


    Depending on your transaction settings (both on your mysql
    connection object in code, and the engine used for the table(s)
    in mysql's DB), you may have to commit your transaction to make
    it visible in other connections. This helps prevent partial
    transactions from being visible when they're in inconsistent states.

    -tkc
     
    Tim Chase, Jan 29, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Little

    can't import MySQldb on OS X

    Alan Little, Jun 25, 2003, in forum: Python
    Replies:
    0
    Views:
    856
    Alan Little
    Jun 25, 2003
  2. Skip Montanaro

    Re: Problem with MySQLdb on Mac OS X...

    Skip Montanaro, Jul 12, 2003, in forum: Python
    Replies:
    5
    Views:
    398
    Michael S. Jessop
    Jul 16, 2003
  3. Mike M
    Replies:
    1
    Views:
    346
  4. Dave Harrison

    MySQLdb and egenix mxDateTime dumps core

    Dave Harrison, Aug 5, 2003, in forum: Python
    Replies:
    0
    Views:
    348
    Dave Harrison
    Aug 5, 2003
  5. Dave Harrison

    using like and % in MySQLdb

    Dave Harrison, Aug 7, 2003, in forum: Python
    Replies:
    0
    Views:
    323
    Dave Harrison
    Aug 7, 2003
Loading...

Share This Page