欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python結(jié)合MySQL數(shù)據(jù)庫編寫簡單信息管理系統(tǒng)完整實例

 更新時間:2023年06月12日 08:36:47   作者:不愛編程的python小白  
最近Python課堂上布置了綜合實訓,實驗目標是設計一個信息管理系統(tǒng),下面這篇文章主要給大家介紹了關于Python結(jié)合MySQL數(shù)據(jù)庫編寫簡單信息管理系統(tǒng)的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下

1,項目整體邏輯及使用工具

1.1 項目整體邏輯

本項目主要是使用Python進行編寫,利用Python中的pymysql庫進行連接數(shù)據(jù)庫,將信息存入MySQL數(shù)據(jù)庫中,然后實現(xiàn)對信息進行增刪改查等一系列操作。

1.2 使用工具

(1):使用pymysql庫

(2):python 3.9

(3):MySQL 8.0

1.3 pymysql庫的安裝

pip install pymysql

2,數(shù)據(jù)庫的搭建

2.1本項目為簡單的信息管理系統(tǒng)的實現(xiàn)

創(chuàng)建數(shù)據(jù)庫一個六個字段分如下:

2.2數(shù)據(jù)庫搭建代碼

create table if not exists information(
    pid int primary key AUTO_INCREMENT,    -- 主鍵
    users varchar(20) not null ,           -- 賬號
    cod varchar(20),                       -- 密碼
    name varchar(20),                      -- 姓名
    age int,                               -- 年齡
    mobile varchar(50)                    -- 電話號碼
);

3,Python代碼編寫

3.1 使用pymysql進行連接數(shù)據(jù)庫

import pymysql
 conn = pymysql.connect(
        host='127.0.0.1',
        port=3306,
        user='root',
        password='123456'
    )
    cus = conn.cursor()  # 創(chuàng)建游標
    sql=""              # 編寫sql語句
    cus.execute(sql)    #使用游標執(zhí)行sql語句
    conn.commit()       #進行提交
    cus.close()    #關閉游標
    conn.close()   #關閉數(shù)據(jù)庫連接

3.2 系統(tǒng)界面進行編寫

print('*' * 54)
print('【1】注冊用戶信息')
print('【2】刪除用戶信息')
print('【3】修改用戶信息')
print('【4】查詢用戶信息')
print('【5】退出系統(tǒng)')
print('*' * 54)
n = input('請輸入你要執(zhí)行的命令')
if n == '1':
   register(cus,conn)
elif n == '2':
    strike(cus, conn)
elif n == '3':
     modify(cus, conn)
elif n == '4':
     inquiry(cus,conn)
elif n == '5':
      cus.close()    #關閉游標
      conn.close()   #關閉數(shù)據(jù)庫連接
      break
else:
     print('輸入錯誤請重新輸入')

3.3 對用戶注冊模塊進行編寫

def register(cus,conn):      #  注冊模塊
    users=input('請輸入用戶賬號')
    cod=input('請輸入用戶密碼')
    name=input('請輸入用戶姓名')
    age=int(input('請輸入用戶年齡'))
    mobile=input('請輸入用戶的手機號')
    sql=f"insert into xinxi.information(users,cod,name,age,mobile) values ('{users}','{cod}','{name}',{age},'{mobile}')"
    cus.execute(sql)
    conn.commit()
    print('注冊成功')
    pass

3.4 對用戶信息刪除模塊進行編寫

def strike(cus,conn):     #刪除用戶
    users = input('請輸入需要刪除的用戶賬號')
    cod = input('請輸入密碼')
    sql = f"select * from xinxi.information where users='{users}' and cod='{cod}'"
    n = cus.execute(sql)
    # conn.commit()   # 提交信息
    # print(n)
    if n:
        sql =f"delete from xinxi.information where users='{users}' and cod='{cod}'"
        cus.execute(sql)
        conn.commit()
        print('刪除成功')
    else:
        print('查無此人')

3.5 對用戶信息修改模塊進行編寫

def modify(cus,conn):  #修改信息
    users=input('請輸入需要修改的用戶賬號')
    cod=input('請輸入密碼')
    sql=f"select * from xinxi.information where users='{users}' and cod='{cod}'"
    n=cus.execute(sql)
    #conn.commit()   # 提交信息
    #print(n)
    if n:
        users1 = input('請輸入需要修改的用戶賬號')
        cod1 = input('請輸入需要修改用戶密碼')
        name = input('請輸入需要修改用戶姓名')
        age = int(input('請輸入需要修改用戶年齡'))
        mobile = input('請輸入需要修改用戶的手機號')
        sql=f"update xinxi.information set users='{users1}',cod='{cod1}',name='{name}',age={age},mobile='{mobile}' where users='{users}' and cod='{cod}'"
        cus.execute(sql)
        conn.commit()
        print('修改成功')
    else:
        print('查無此人')

3.6 對用戶信息查詢模塊進行編寫

def inquiry(cus,conn):     #查詢信息
    users = input('請輸入需要查詢的用戶賬號')
    cod = input('請輸入密碼')
    sql = f"select * from xinxi.information where users='{users}' and cod='{cod}'"
    n = cus.execute(sql)
    if n:
        sql = f"select name,age,mobile from xinxi.information where users='{users}' and cod='{cod}'"
        cus.execute(sql)      #接收數(shù)據(jù)
        u=cus.fetchall()
        #conn.commit()
        print('用戶的姓名為:',u[0][0])
        print('用戶的年齡為:',u[0][1])
        print('用戶的電話為',u[0][2])
    else:
        print('查無此人')

4,系統(tǒng)整體代碼

# 需求,登陸后會用戶進行查詢
import pymysql


def main():
    conn = pymysql.connect(
        host='127.0.0.1',
        port=3306,
        user='root',
        password='123456'
    )
    cus = conn.cursor()  # 創(chuàng)建
    while True:
        print('*' * 54)
        print('【1】注冊用戶信息')
        print('【2】刪除用戶信息')
        print('【3】修改用戶信息')
        print('【4】查詢用戶信息')
        print('【5】退出系統(tǒng)')
        print('*' * 54)
        n = input('請輸入你要執(zhí)行的命令')
        if n == '1':
            register(cus,conn)
        elif n == '2':
            strike(cus, conn)
        elif n == '3':
            modify(cus, conn)
        elif n == '4':
            inquiry(cus,conn)
        elif n == '5':
            cus.close()    #關閉游標
            conn.close()   #關閉數(shù)據(jù)庫連接
            break
        else:
            print('輸入錯誤請重新輸入')

def register(cus,conn):      #  注冊模塊
    users=input('請輸入用戶賬號')
    cod=input('請輸入用戶密碼')
    name=input('請輸入用戶姓名')
    age=int(input('請輸入用戶年齡'))
    mobile=input('請輸入用戶的手機號')
    sql=f"insert into xinxi.information(users,cod,name,age,mobile) values ('{users}','{cod}','{name}',{age},'{mobile}')"
    cus.execute(sql)
    conn.commit()
    print('注冊成功')
    pass

def strike(cus,conn):     #刪除用戶
    users = input('請輸入需要刪除的用戶賬號')
    cod = input('請輸入密碼')
    sql = f"select * from xinxi.information where users='{users}' and cod='{cod}'"
    n = cus.execute(sql)
    # conn.commit()   # 提交信息
    # print(n)
    if n:
        sql =f"delete from xinxi.information where users='{users}' and cod='{cod}'"
        cus.execute(sql)
        conn.commit()
        print('刪除成功')
    else:
        print('查無此人')

def modify(cus,conn):  #修改信息
    users=input('請輸入需要修改的用戶賬號')
    cod=input('請輸入密碼')
    sql=f"select * from xinxi.information where users='{users}' and cod='{cod}'"
    n=cus.execute(sql)
    #conn.commit()   # 提交信息
    #print(n)
    if n:
        users1 = input('請輸入需要修改的用戶賬號')
        cod1 = input('請輸入需要修改用戶密碼')
        name = input('請輸入需要修改用戶姓名')
        age = int(input('請輸入需要修改用戶年齡'))
        mobile = input('請輸入需要修改用戶的手機號')
        sql=f"update xinxi.information set users='{users1}',cod='{cod1}',name='{name}',age={age},mobile='{mobile}' where users='{users}' and cod='{cod}'"
        cus.execute(sql)
        conn.commit()
        print('修改成功')
    else:
        print('查無此人')

def inquiry(cus,conn):     #查詢信息
    users = input('請輸入需要查詢的用戶賬號')
    cod = input('請輸入密碼')
    sql = f"select * from xinxi.information where users='{users}' and cod='{cod}'"
    n = cus.execute(sql)
    if n:
        sql = f"select name,age,mobile from xinxi.information where users='{users}' and cod='{cod}'"
        cus.execute(sql)      #接收數(shù)據(jù)
        u=cus.fetchall()
        #conn.commit()
        print('用戶的姓名為:',u[0][0])
        print('用戶的年齡為:',u[0][1])
        print('用戶的電話為',u[0][2])
    else:
        print('查無此人')

if __name__ == '__main__':
    main()

使用本程序需要安裝MySQL數(shù)據(jù)庫并創(chuàng)建數(shù)據(jù)庫。

總結(jié)

到此這篇關于Python結(jié)合MySQL數(shù)據(jù)庫編寫簡單信息管理系統(tǒng)的文章就介紹到這了,更多相關Python MySQL編寫信息管理系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Python如何將給定字符串中的大寫英文字母按以下對應規(guī)則替換

    Python如何將給定字符串中的大寫英文字母按以下對應規(guī)則替換

    這篇文章主要介紹了Python如何將給定字符串中的大寫英文字母按以下對應規(guī)則替換,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • PyCharm最新激活碼(2020/10/27全網(wǎng)最新)

    PyCharm最新激活碼(2020/10/27全網(wǎng)最新)

    Pycharm最新激活碼全網(wǎng)最新(2020/10/27更新),適用Intellij idea 2020.2.x,WebStorm 2020.2.x,Pycharm 2020.2.x
    2020-10-10
  • python中的格式化輸出方法

    python中的格式化輸出方法

    這篇文章主要介紹了python中的格式化輸出方法,?數(shù)據(jù)可以以人類可讀的形式打印,或?qū)懭胛募怨硎褂茫踔量梢砸阅撤N其他指定的形式。?用戶通常希望對輸出格式進行更多控制,而不是簡單地打印以空格分隔的值,更多格式化輸出方式需要的朋友可以參考下面文章內(nèi)容
    2022-03-03
  • 淺談Django自定義模板標簽template_tags的用處

    淺談Django自定義模板標簽template_tags的用處

    這篇文章主要介紹了淺談Django自定義模板標簽template_tags的用處,具有一定借鑒價值,需要的朋友可以參考下。
    2017-12-12
  • Python文件如何引入?詳解引入Python文件步驟

    Python文件如何引入?詳解引入Python文件步驟

    我們整理了一篇關于引入Python文件的一個基礎知識點內(nèi)容,如果你是一個python的學習者,參考一下吧。
    2018-12-12
  • Python小技巧練習分享

    Python小技巧練習分享

    這篇文章主要介紹了Python小技巧練習分享,文章基于python的相關內(nèi)容展開詳細的python小技巧內(nèi)容,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-05-05
  • SageMath與Python的使用示例教程

    SageMath與Python的使用示例教程

    SageMath是一個開源的數(shù)學軟件,它可以與Python進行交互,本文通過實例代碼介紹了SageMath與Python的使用,需要的朋友可以參考下
    2024-03-03
  • wxpython+pymysql實現(xiàn)用戶登陸功能

    wxpython+pymysql實現(xiàn)用戶登陸功能

    這篇文章主要介紹了wxpython+pymysql實現(xiàn)用戶登陸功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • python實現(xiàn)停車場管理系統(tǒng)

    python實現(xiàn)停車場管理系統(tǒng)

    這篇文章主要為大家詳細介紹了python實現(xiàn)停車場管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • 用matplotlib畫等高線圖詳解

    用matplotlib畫等高線圖詳解

    這篇文章主要介紹了用matplotlib畫等高線圖詳解,具有一定借鑒價值,需要的朋友可以參考下。
    2017-12-12

最新評論