
7
章のコード
7
章 データベースの利用
you are here
307
import mysql.connector
def log_request(req: 'flask_request', res: str) -> None:
"""Web
リクエストの詳細と結果をロギングする。
"""
dbconfig = { 'host': '127.0.0.1',
'user': 'vsearch',
'password': 'vsearchpasswd',
'database': 'vsearchlogDB', }
conn = mysql.connector.connect(**dbconfig)
cursor = conn.cursor()
_SQL = """insert into log
(phr
ase, letters, ip, browser_string, results)
values
(%s, %s, %s, %s, %s)"""
cursor.execute(_SQL, (req.form['phrase'],
req.form['letters'],
req.remote_addr,
req.user_agent.browser,
res, ))
conn.commit()
cursor.close()
conn.close()
dbconfig = { 'host': '127.0.0.1',
'user': 'vsearch',
'password': 'vsearchpasswd', ...