import pymysql.cursors

# Conectando ao banco de dados
connection = pymysql.connect(host='', unix_socket='/tmp/mysql.sock',
                       user='', passwd='', db='')

try:
    with connection.cursor() as cursor:
        # Create a new record
        sql = "INSERT INTO tabela (col1, col2) VALUES ('var1', 'var2')"
        cursor.execute(sql)

    # connection is not autocommit by default. So you must commit to save
    # your changes.
    connection.commit()
finally:
    connection.close()

E para listar:

from __future__ import print_function

import pymysql

conn= pymysql.connect(host='', unix_socket='/tmp/mysql.sock',
                       user='', passwd='', db='')
cur = conn.cursor()

cur.execute("SELECT post_title, post_content FROM wp_posts LIMIT 0,10;")

print(cur.description)

print()

for row in cur:
    print(row)

cur.close()
conn.close()

import pymysql 
db = pymysql.connect(host='', unix_socket='/tmp/mysql.sock',
	            user='', passwd='', db='rafaelrjp20')
cur = db.cursor(pymysql.cursors.DictCursor)


sql = "SELECT url FROM tabela WHERE arquivo is null or imagem is null order by id desc limit 0,1;"
cur.execute(sql)
for row in cur:
    print(row['url'])
    info_single_page(row['url'])
Este artigo foi útil ?
SimNão

6 Replies to “Python conectando ao Mysql”

  1. 33wim disse:

    Alright, 33wim, let’s see what you’ve got! Hope the experience is smooth and the wins are plentiful. Wish me luck! Check them out here 33wim.

  2. Okay, 3pattiluckyapk is the real deal if you’re into teen patti. Downloaded the APK, and it runs smoothly. If you’re a fan, check it out 3pattiluckyapk.

  3. vsp777game disse:

    VSP777game! Classic vibes, man. Slots and stuff. Easy to get into, but be careful, it can be a time sink! Find it here vsp777game.

  4. 939betcomapp disse:

    Downloaded the 939betcomapp the other day. It’s actually pretty smooth. Navigation is easy, and placing bets is a breeze. I’d recommend giving it a shot if you’re into mobile betting. More details here: 939betcomapp

  5. 55666 bong88 disse:

    Alright, 55666 bong88 is the real deal. I’ve had some decent wins on this site. The interface is clean and easy to navigate, which is a major plus. Give it a shot! 55666 bong88

  6. bet20plays disse:

    Bet20plays – never heard of it, but I gave it a try. UI is good, easy to use. Games are okay, nothing groundbreaking though. Give it a whirl if you’re bored! Find it at: bet20plays

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Close Search Window