Search
 
SCRIPT & CODE EXAMPLE
 

SQL

flask connect to mysql

from flask import Flask,render_template, request
from flask_mysqldb import MySQL
 
app = Flask(__name__)
 
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = 'flask'
 
mysql = MySQL(app)
 
@app.route('/form')
def form():
    return render_template('form.html')
 
@app.route('/login', methods = ['POST', 'GET'])
def login():
    if request.method == 'GET':
        return "Login via the login Form"
     
    if request.method == 'POST':
        name = request.form['name']
        age = request.form['age']
        cursor = mysql.connection.cursor()
        cursor.execute(''' INSERT INTO info_table VALUES(%s,%s)''',(name,age))
        mysql.connection.commit()
        cursor.close()
        return f"Done!!"
 
app.run(host='localhost', port=5000)
Comment

flask connect to mssql

# Python 2.x
import urllib
params = urllib.quote_plus("DRIVER={SQL Server Native Client 10.0};SERVER=dagger;DATABASE=test;UID=user;PWD=password")
engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)

# Python 3.x
import urllib
params = urllib.parse.quote_plus("DRIVER={SQL Server Native Client 10.0};SERVER=dagger;DATABASE=test;UID=user;PWD=password")
engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)


# using the above logic I just did the following
params = urllib.parse.quote_plus('DRIVER={SQL Server};SERVER=HARRISONS-THINK;DATABASE=LendApp;Trusted_Connection=yes;')
app.config['SQLALCHEMY_DATABASE_URI'] = "mssql+pyodbc:///?odbc_connect=%s" % params
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql find max value row 
Sql :: mysql select row with max value group by 
Sql :: multiple order by sql 
Sql :: oracle get foreign keys on table 
Sql :: mysql if statement in where clause 
Sql :: how to get last inserted id in sql server c# 
Sql :: sql like case sensitive 
Sql :: rebuild index sql server 
Sql :: get stored procedure text sql server 
Sql :: mysqldump 1 table only 
Sql :: mysql search replace 
Sql :: Write SQL in ruby on rails 
Sql :: match in sql server 
Sql :: DELETE DUPLICATE VALUES FROM A TABLE IN SQL SERVER 
Sql :: min mysql 
Sql :: 2 max value in sql 
Sql :: delete insert record in sql server 
Sql :: mysql pad zeros 
Sql :: demmarrer un service mysql teminal cmd 
Sql :: postgresql find blocked query 
Sql :: sqlite create record 
Sql :: mysql autoincrement valor inicial 
Sql :: alter in sql 
Sql :: npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! sqlite3@4.2.0 install: `node-pre-gyp install --fallback-to-build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the sqlite3@4.2.0 install script. 
Sql :: SQL:RANK function to delete duplicate rows 
Sql :: how to use select union and loop 
Sql :: max mysql 
Sql :: sqlalchemy default value for column 
Sql :: sql alter table 
Sql :: insert command in sql 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =