最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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()    #關(guān)閉游標
    conn.close()   #關(guān)閉數(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()    #關(guān)閉游標
      conn.close()   #關(guān)閉數(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()    #關(guān)閉游標
            conn.close()   #關(guān)閉數(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é)

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

相關(guān)文章

  • python re模塊findall()函數(shù)實例解析

    python re模塊findall()函數(shù)實例解析

    這篇文章主要介紹了python re模塊findall()函數(shù)實例解析,具有一定借鑒價值,需要的朋友可以參考下
    2018-01-01
  • Python實現(xiàn)列表索引批量刪除的5種方法

    Python實現(xiàn)列表索引批量刪除的5種方法

    這篇文章主要介紹了Python實現(xiàn)列表索引批量刪除的5種方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • python手機號前7位歸屬地爬蟲代碼實例

    python手機號前7位歸屬地爬蟲代碼實例

    這篇文章主要介紹了python手機號前7位歸屬地爬蟲代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-03-03
  • Python中的枚舉類型示例介紹

    Python中的枚舉類型示例介紹

    這篇文章主要給大家介紹了關(guān)于Python中枚舉類型的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • python的mysql數(shù)據(jù)庫建立表與插入數(shù)據(jù)操作示例

    python的mysql數(shù)據(jù)庫建立表與插入數(shù)據(jù)操作示例

    這篇文章主要介紹了python的mysql數(shù)據(jù)庫建立表與插入數(shù)據(jù)操作,結(jié)合實例形式分析了python操作mysql數(shù)據(jù)庫建立表與插入數(shù)據(jù)相關(guān)實現(xiàn)技巧,需要的朋友可以參考下
    2019-09-09
  • Python實現(xiàn)帶GUI界面的手寫數(shù)字識別

    Python實現(xiàn)帶GUI界面的手寫數(shù)字識別

    這篇文章主要介紹了如何通過Python實現(xiàn)帶GUI界面的手寫數(shù)字識別,文中的示例代碼講解詳細,對我們學(xué)習(xí)Python有一定的幫助,感興趣的可以了解一下
    2022-01-01
  • Pycharm通過SSH、SFTP連接遠程服務(wù)器實踐

    Pycharm通過SSH、SFTP連接遠程服務(wù)器實踐

    本文介紹在PyCharm專業(yè)版中配置SSH/SFTP連接遠程服務(wù)器實現(xiàn)代碼編輯調(diào)試的步驟,包括新建項目選擇已有解釋器、設(shè)置服務(wù)器參數(shù)、配置Rootpath與文件映射、啟用自動上傳下載功能,確保遠程開發(fā)環(huán)境與本地同步
    2025-07-07
  • Python中創(chuàng)建包和增添包的路徑(sys.path.append())

    Python中創(chuàng)建包和增添包的路徑(sys.path.append())

    本文主要介紹了Python中創(chuàng)建包和增添包的路徑(sys.path.append()),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-01-01
  • python3.6使用pymysql連接Mysql數(shù)據(jù)庫

    python3.6使用pymysql連接Mysql數(shù)據(jù)庫

    這篇文章主要為大家詳細介紹了python3.6使用pymysql連接Mysql數(shù)據(jù)庫,以及簡單的增刪改查操作,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Python中 pickle 模塊的 dump() 和 load() 方法詳解

    Python中 pickle 模塊的 dump() 和 load()&

    Python 的 pickle 模塊用于實現(xiàn)二進制序列化和反序列化,一個對象可以被序列化到文件中,然后可以從文件中恢復(fù),這篇文章主要介紹了Python中 pickle 模塊的 dump() 和 load() 方法詳解,需要的朋友可以參考下
    2022-12-12

最新評論

乌鲁木齐县| 平阴县| 泽州县| 开平市| 承德县| 青阳县| 龙海市| 积石山| 彩票| 湖州市| 偏关县| 柞水县| 游戏| 房山区| 平陆县| 绥江县| 梓潼县| 邵东县| 岱山县| 武隆县| 福州市| 南丹县| 桑植县| 曲沃县| 湖南省| 右玉县| 乐清市| 韶山市| 临沧市| 辽中县| 南安市| 广丰县| 衡阳市| 武汉市| 改则县| 永定县| 寿光市| 夏津县| 马龙县| 崇文区| 东乡族自治县|