Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何向MySQL表中插入数据 #75

Open
Sogrey opened this issue Feb 17, 2020 · 0 comments
Open

如何向MySQL表中插入数据 #75

Sogrey opened this issue Feb 17, 2020 · 0 comments
Labels
数据存储 文件存储,数据库存储
Projects

Comments

@Sogrey
Copy link
Owner

Sogrey commented Feb 17, 2020

insert

def insertRecords(db):
    cursor = db.cursor()
    try:
        cursor.execute('delete from persons')
        cursor.execute('''
        insert into persons(id,name,age,address,salary)
        values(1,'Bill',32,'California',20000)
        ''')
        cursor.execute('''
        insert into persons(id,name,age,address,salary)
        values(2,'Mike',30,'Texas',10000)
        ''')

        cursor.execute('''
        insert into persons(id,name,age,address,salary)
        values(3,'John',45,'Norway',30000)
        ''')
        db.commit()
        return True
    except Exception as e:
        print(e)
        db.rollback()
    return False
if insertRecords(db):
    print('成功插入记录')
else:
    print('插入记录失败')

如何创建MySQL数据表 #74

@Sogrey Sogrey added the 数据存储 文件存储,数据库存储 label Feb 17, 2020
@Sogrey Sogrey added this to 数据存储 in Python QAs Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
数据存储 文件存储,数据库存储
Projects
Python QAs
数据存储
Development

No branches or pull requests

1 participant