Guest User

Untitled

a guest
Feb 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import mysql.connector
  2.  
  3. mydb = mysql.connector.connect(
  4. user='root',
  5. host='localhost',
  6. password='***')
  7.  
  8. mycursor = mydb.cursor()
  9.  
  10. mycursor.execute("select calldate, clid, src, dst from cdr.cdr
  11. where calldate like '2019-02-18%'
  12. ORDER BY calldate desc limit 2")
  13.  
  14. myresult = mycursor.fetchall()
  15.  
  16. for row in myresult:
  17. for fild in row:
  18. print (fild[0])
  19. print (fild[1])
  20. print (fild[2])
  21. print (fild[3])
  22.  
  23. mydb.close()
  24.  
  25. # python3.6 dumpMysql.py
  26. Traceback (most recent call last):
  27. File "dumpMysql.py", line 18, in <module>
  28. print (fild[0])
  29. TypeError: 'datetime.datetime' object is not subscriptable
  30.  
  31. Primeira linha do select
  32. campo0
  33. campo1
  34. campo2
  35. campo3
  36.  
  37. Segunda linha do select
  38. campo0
  39. campo1
  40. campo2
  41. campo3
Add Comment
Please, Sign In to add comment