2015-12-15 2 views
5

mysql/mysql-pythonコネクタにpython-2.7とnewbieを使用しています。mysql-pythonを使用してSelect文を実行すると、Noneが返されます。

私はただ単にquery-

SELECT D_ID、d_link、d_details

FROM d_nameしかし、それは/がなしを返さない与え、以下の使用してデータを取得します。続いてクエリがどのような形態で

ヘルプ/ガイダンスは歓迎されているワークベンチでうまく動作しますが、私のコード -

def getdbconnection(self): 

    try: 

     self.cnx = mysql.connector.connect(user='abc',password='xxx',host = 'localhost',port = 'xxx', database='details',buffered=True)  

     print "Done" 
     self.cursor = self.cnx.cursor() 

    except MySQLdb.Error as error:  
       print "ERROR IN CONNECTION" 

def selectst(self): 
     try: 
        print "S E L E C T" 
        self.d_deta = self.cursor.execute("SELECT d_id,d_link,d_name FROM `d_details`") 
        print self.d_deta 


     except MySQLdb.Error as error: 
          print "---------------------""" 
          print(error) 
     self.cnx.commit() 

、出力が

Done 

    S E L E C T 

    None 

です。

+1

試し '印刷self.cursor.fetchall()' – The6thSense

+0

@VigneshKalaiを使用しました! –

+0

お手伝いします:) – The6thSense

答えて

1

あなたはこの

コードのようにコードを変更する必要があります

def selectst(self): 
    try: 
      print "S E L E C T" 
      self.cursor.execute("SELECT d_id,d_link,d_name FROM `d_details`") 
      print self.cursor.fetchall() # or fetchone() for one record 

    except MySQLdb.Error as error: 
         print "---------------------""" 
         print(error) 
    #self.cnx.commit() there is no need of commit here since we are not changing the data of the table 

ノート:

  • あなたはcursor.executeははlist.sortのようなメモリの動作であるなしので取得します()
  • 行はbうまく機能どうもありがとう - eはcursor objectを反復処理またはfetch*()
関連する問題