Sunday 15 August 2010

mysql - MySQLdb / Python / LocalHost - Query runs without error but no result -


Am I expecting someone to help me? I'm trying to populate a MySQL database using Python 2.7 and MySQLdb library. I have written the sample script below, but whatever I try, I can not get it to work.

The code runs without any errors (when I run the code, but 'full' prints it is the same) and when I try to query directly in phpMyAdmin it works fine, For some reason I can not work it from within Python.

Did I miss something? Do I need to do some work to activate in phpMyAdmin? I am searching for answers mostly around noon, when other people have such problems, although they receive the error message (which I do not).

  Import MySQLdb # Define the details of database access DB_HOST = "localhost" db_user = "user name" db_password = "password password" db_NAME = "testdatabase" # relate to database db = MySQLdb.connect (Host = DB_HOST, user = DB_USER, passwd = DB_PASSWORD, db = DB_NAME) cur = db.cursor () Question = "Insert search in search (` timestamp`, `searchTerm`,` search keyword`) value ('2013-06- 22 17:28:09', 'TestSearchTerm', 'Test Search Results'); "Cur.execute" printed "done"   

This is my first experience so that I make some clarity, please forgive me! Any help would be appreciated!

You may change commit () .


This is your "first experience" some explanations:

Depending on the capabilities of your "database engine", when you modify your data, your changes occur Are not immediately visible for "outer world", casually, your changes are "private" for your database connection.

This is a very important feature among others, there are benefits to allow you to make many changes in it - and one more benefit to "publish" them at one time is that if you decide on a decision If they are not valid, you can "cancel" without disturbing any other user of your database.

A slight flaw of it, do you ever make your changes, once you are ready to publish them. Otherwise, they disappear after the connection is closed. You also get the opportunity to set up "AutoCommit" - which will be untrue after every DB request. Depending on your requirements, this might be an option to summarize:

  • "Publish" your change in DB: db.commit () , < / Li>
  • Use "Cancel" for your changes. For DB: Use db.rollback () or just turn off the connection without having to go, < Li> Due to each request: db.autocommit (True)

    DBA and other database for overlapping of the above paragraphs Iseshjtr probably cry but I hope it will help you understand what's going on!

No comments:

Post a Comment