Python String Formats with SQL Wildcards and LIKE

后端 未结 6 913
情深已故
情深已故 2020-11-30 11:04

I\'m having a hard time getting some sql in python to correctly go through MySQLdb. It\'s pythons string formatting that is killing me.

My sql statement is using the

6条回答
  •  被撕碎了的回忆
    2020-11-30 11:40

    import mysql.connector
    mydatabase = mysql.connector.connect(host="localhost", user="root", passwd="1234", database="databaseName")
    mycursor = mydatabase.cursor()
    user_input =[]
    item = str("s%")
    user_input.append(item)
    mycursor.execute("SELECT * FROM employees WHERE FIRST_NAME LIKE %s ESCAPE ''",user_input )
    result = mycursor.fetchall()
    for row in enumerate(result):
        print(row)
    

提交回复
热议问题