Reputation: 11
i am trying to connect the database mysql using flask-python . i create a 'users' name table have two columns 'fname' 'lname' datatype string in my database name 'login'
code
from flask import Flask
from flask_mysqldb import MySQL
app=Flask(__name__)
app.config['MYSQL_HOST']='localhost'
app.config['MYSQL_PORT']='3306'
app.config['MYSQL_USER']='root'
app.config['MYSQL_PASSWORD']='12345'
app.config['MYSQL_DB']='login'
mysql=MySQL(app)
@app.route('/insert')
def insert():
fname="arslan"
lname="arshad"
cur=mysql.connection.cursor()
cur.execution("INSERT INTO users(fname,lname) VALUES(%s,%s)",(fname,lname))
mysql.connection.commit()
cur.close()
return "inserted"
app.run(debug=True)
ERROR:
TypeError TypeError: 'str' object cannot be interpreted as an integer
Upvotes: 0
Views: 1277
Reputation: 11
I find my Error, i was using string value ..
app.config['MYSQL_PORT']='3306' ##wrong
app.config['MYSQL_PORT']=3306 ##correct
function accept a integer value so error show TypeError: 'str' object cannot be interpreted as an integer
Upvotes: 1