python database connection function

With python build a function, a database query each time they connect directly call on the line


 

# Introduction of related modules 
Import
pymysql from SQLAlchemy Import create_engine
DEF Query (Table): 
    Host = ' localhost '     # local IP address 
    User = ' the root '     # username 
    passward = ' 123456 '     # database password 
    Database = ' Test '     # database name 
    Port = 3306     # database port 
    Conn = create_engine ( ' + pymysql MySQL: // {}: {}} {@: {} / {} ' .format (User, passward, Host, Port, database))     # database connection statements 
    SQL = ' SELECT * from ' +  STR (Table )
    Results=pd.read_sql(sql,conn)
    return results

 

 

 

Guess you like

Origin www.cnblogs.com/lattesea/p/12468402.html