Python about MySQL connection plug-ins, bottle is also someone specifically developed plug-ins: Bottle-mysql specific use method see official, total feel its usage limit too much, its use inconvenient, the most suitable of course is, The common official driver of the MySQL website for Python is handy: Mysql-connector the following:
#-*-Coding:utf-8-*-#!/usr/bin/python# filename:login_admin.py# codedtime:2014-9-7 11:26:11import bottleimport MySQL . Connector # import MySQL database connector def check_userinfo (): A_list = [] # Create an empty list username = bottle.request.GET.get (' LoginName ', ' ). Strip () # user name password = bottle.request.GET.get (' password ', '). Strip () # password if username is not None or password is no T none:try: # CONNECT Database conn = Mysql.connector.connect (user= ' root ', password= ' 123456 ', database= ' MyBlog ') cursor = Conn.cursor () # Create data cursor # Execute query = ("Select username, password from mb_users" "W Here username=%s and password=%s ") Cursor.execute (query, (username, password)) A_list = Cursor.fetchall () # FETC Hone get a tuple #count = Int (cursor.rowcount) # Gets the number of tuples return a_list except Mysql.connector.Error as ERR:PR Int ("Something went wrong: {}". Format (Err)) exit () Finally:conn.commit () # Commit Modify Cursor.close () # Close Database Conn.close ()Else:return a_listdef login_admin (): If Bottle.request.GET.get (' Bs-submit ', '). Strip (): #点击登录按钮 a_list = Check_use Rinfo () If a_list:a_name = a_list[0][0] # Get user name return Bottle.template (' Templates/index_user.tpl ', username = A_name) Else:return bottle.template (' Templates/login_admin.tpl ', action= '/login_admin ', Error_inf O= ' Please enter the correct username or password! ') Else:return bottle.template (' Templates/login_admin.tpl ', action= ', error_info= ')
These are the simple uses of MySQL in Botlle,
By the way: installation and management of MySQL, it is recommended to install the use of XAMPP,XAMPP integrated Apache, MySQL, PHP, Tomcat and other tools, one-time solution installation, without their own cumbersome installation and configuration, and management is also very convenient. XAMPP installed MySQL Default user is: The root password is empty.