PYTH COUNT MYSQL.Connector

PYTH COUNT MYSQL.Connector - Python - Programmation

Marsh Posté le 28-09-2017 à 10:10:10    

Hello
Voila une bonne grosse méthode de bourrin (la mienne) pour trouver le nombre de lignes d'une table.
J'arrive pas à capter comment faire un count avec MYSQL.Connector
Quelqu'un peut-il me sortir un exemple simple ?
Merci beaucoup

Code :
  1. cursor1_1 = cnx_1.cursor(buffered=True)
  2. ligne = "SELECT has_title FROM base WHERE 1"
  3. try:
  4.     cursor1_1.execute(ligne)
  5.     for row in cursor1_1:
  6.         nbligne=nbligne+1
  7. except:
  8.     print "erreur"
  9. else:
  10.     print nbligne,"lignes"


---------------
http://www.ypikay.com
Reply

Marsh Posté le 28-09-2017 à 10:10:10   

Reply

Marsh Posté le 01-10-2017 à 14:01:38    

Connais pas MYSQL.Connector, mais je présume que c'est compatible DBAPI 2.0, donc:

Code :
  1. with cnx_1.cursor() as cr:
  2.    cr.execute('SELECT count(*) FROM table')
  3.    count = cr.fetchone()


[:spamafote]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 01-10-2017 à 20:31:11    

Merci je vais essayer ça !!


---------------
http://www.ypikay.com
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed