Use pymysql connected database in python

# Import pymysql 
Import pymysql

# Connection server 
Conn = pymysql.connect (
    Host = ' 127.0.0.1 ' ,      # the MySQL Address 
    Port = 3306,      # the MySQL port 
    User = ' the root ' ,      # the MySQL username 
    password = ' 123 ' ,      # the MySQL password 
    DB = 'Test ' ,      # selected library 
    charset = ' UTF8 ' ,      # set the character encoding 
    the autocommit = True      # automatically submitted after setting CRUD 
)

# Create a cursor, and set the return value of the dictionary 
the Cursor = conn.cursor (the Cursor = pymysql.cursors.DictCursor)

# The user input 
USER_NAME = INPUT ( ' USER_NAME: ' ) .strip ()
pwd = input('pwd:').strip()

# 拼接sql语句
sql = 'select * from user_info where name=%s and pwd=%s'

# Execute sql statement 
cursor.execute (sql, (user_name, pwd ))

# Receives the return value 
Data = cursor.fetchone ()

# The return value 
IF Data:
     Print ( ' successful login ' )
 the else :
     Print ( " Login Failed " )

 

Guess you like

Origin www.cnblogs.com/hellozizi/p/11401085.html