We know that python3.x introduced a new string format syntax. Different from the python2.x
Copy Code code as follows:
Python3.x is
Copy Code code as follows:
' {0} {1} '. Format (A,B)
Today, when I use MYSQLDB, I need to use a parameter
Copy Code code as follows:
Cursor.execute (Sql,param)
Statement to complete the SQL operation. Be misled by the old sayings of other articles, using the
Copy Code code as follows:
Cursor.execute (' INSERT into test values (%s,%s,%s) ', param)
Where Param is a tuple that represents the data to be inserted, and each element in the tuple is the value of each column in the database.
But execution always throws a database exception, an error message:
Copy Code code as follows:
"1064" You have a error in your SQL syntax; Check the manual that corresponds to your MySQL server version for the right syntax to use near ' (%s,%s,%s) ' in line ... (omitted below).
In fact, as long as the change to this is good:
Copy Code code as follows:
Cursor.execute (' INSERT into test values ({0},{1},{2}) ', param)
To tell the truth, Python3 in order to fill in the Python2 of the pits led to backward, making learning Python3 cost improved a lot. But in order not to hinder the development of science and technology, social progress, I still resolutely devote to the new version ...