[Python] mysql.connector.connect failing to connect

Discussão em 'Python' iniciado por Stack, Fevereiro 2, 2025.

  1. Stack

    Stack Membro Participativo

    While trying to connect Python with SQL, it just does not work, with no errors, the execution stops itself, here's the code:

    import mysql.connector

    def appen():
    print('k')
    mysq = mysql.connector.connect(user = 'root',passwd = 'manager',host = 'localhost', database = 'krishna')
    print('g')
    cur = mysq.cursor()
    print('h')
    for i in range(int(input('How many : '))):
    eno = int(input('Eno : '))
    enm = input('Name : ')
    job = input('Job : ')
    mgr = int(input('Mgr : '))
    hd = input('Hired date(YYYY-MM-DD) : ')
    sal = int(input('Salary : '))
    cm = int(input('Comm : '))
    dn = int(input('Dn : '))
    try:
    cur.execute(f"insert into employee values({eno},'{enm}','{job}',{mgr},'{hd}',{sal},{cm},{dn});")
    cur.commit()
    except:
    cur.rollback()
    cur.close()
    mysq.close()

    appen()


    the only output I am getting is :

    k

    Continue reading...

Compartilhe esta Página