Найти - Пользователи
Полная версия: ЗАпист в базу
Начало » Python для новичков » ЗАпист в базу
1
Areostar
 import pymysql.cursors
connection = pymysql.connect(host='127.0.0.1', user='root', password='', db='testdb', cursorclass=pymysql.cursors.DictCursor)
try:
     with connection.cursor() as cursor:
            # Create a new record
            sql = "INSERT INTO `test_table` (`login`, `password`, `hash`) VALUES (%s, %s, %s)"
            cursor.execute(sql, ('webpython.oqrg', 'very02qqq3sddf', 'rwe5G1sd##@1d!sdfsdf'))
            # connection is not autocommit by default. So you must commit to save
            # your changes.
           connection.commit()
finally:
        connection.close()

Так добавляется одна запись? а как добавить сразу несколько, кпримеру сразу 10 или 20
ZerG
executemany
Areostar
Спасибою уже и сам нащёл
 cursor.executemany(sql, collection)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB