N
N
NothingMakesSense2022-01-07 03:11:18
MySQL
NothingMakesSense, 2022-01-07 03:11:18

How to pass long text in query to MySQL from python?

I need to store the text along with hyphens, but the mysql library for python requires sending the request as a string, in which the correct transfer of hyphens cannot be arranged.
I write a query like:

query = "INSERT INTO table (id, name, text) " + 
"VALUES (" + str(id) + ", \'" + name + "\', \'" + text + "\') "

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2022-01-07
@NothingMakesSense

Data must be sent separately.

query = "INSERT INTO table (id, name, text) VALUES (%s, %s, %s)"
cursor.execute(query, (id, name, text))

https://dev.mysql.com/doc/connector-python/en/conn...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question